Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //works only for mongo 2.2
- //works better if you use mongo-hacker (https://github.com/TylerBrock/mongo-hacker)
- var ns ="products.products";
- var key = {partnerId : 1, id : 1}; //the shard key of the collection
- if (typeof colorize != "function") colorize = function(s) {return s};
- var zeroChunk =0
- var chunkSize = db.getSiblingDB("config").settings.findOne({_id : "chunksize"}).value; //target chunkSize in mb
- db.getSiblingDB("config").chunks.find({ns : ns}).limit(500).forEach(function(chunk) {
- var ds = db.getSiblingDB(ns.split(".")[0]).runCommand({datasize:chunk.ns,keyPattern:key,min:chunk.min,max:chunk.max});
- if (ds.numObjects ==0)
- zeroChunk++;
- else {
- if (ds.size > chunkSize*1024 *1024) color = "red"; else color = "black";
- print("Chunk: "+chunk._id +" has a size of "+colorize(ds.size,color)+", and includes "+ds.numObjects+" objects (took "+ds.millis+"ms)")
- }
- }
- )
- print(zeroChunk*100/db.getSiblingDB("config").chunks.find({ns : ns}).count() + " chunks were empty");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement