Created
June 30, 2011 15:32
-
-
Save jasonrdsouza/1056481 to your computer and use it in GitHub Desktop.
MongoDB printShardingStatus javascript function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function printShardingInfo(configDB, verbose) { | |
if (configDB === undefined) { | |
configDB = db.getSisterDB("config"); | |
} | |
var version = configDB.getCollection("version").findOne(); | |
if (version == null) { | |
print("not a shard db!"); | |
return; | |
} | |
var raw = ""; | |
var output = function (s) { | |
raw += s + "\n"; | |
}; | |
//output("--- Sharding Status --- "); | |
output(" sharding version: " + tojson(configDB.getCollection("version").findOne())); | |
output(" shards:"); | |
//configDB.shards.find().forEach(function (z) { | |
// output(" " + tojson(z)); | |
//}); | |
//output(" databases:"); | |
configDB.databases.find().sort({ | |
name: 1 | |
}).forEach(function (db) { | |
//output("\t" + tojson(db, "", true)); | |
if (db.partitioned) { | |
configDB.collections.find({ | |
_id: new RegExp("^" + db._id + ".") | |
}).sort({ | |
_id: 1 | |
}).forEach(function (coll) { | |
if (coll.dropped == false) { | |
output("\t\t" + coll._id + " chunks:"); | |
res = configDB.chunks.group({ | |
cond: { | |
ns: coll._id | |
}, | |
key: { | |
shard: 1 | |
}, | |
reduce: function (doc, out) { | |
out.nChunks++; | |
}, | |
initial: { | |
nChunks: 0 | |
} | |
}); | |
var | |
totalChunks = 0; | |
res.forEach(function (z) { | |
totalChunks += z.nChunks; | |
output("\t\t\t\t" + z.shard + "\t" + z.nChunks); | |
}); | |
//if (totalChunks < 10 || verbose) { | |
// configDB.chunks.find({ | |
// ns: coll._id | |
// }).sort({ | |
// min: 1 | |
// }).forEach(function (chunk) { | |
// output("\t\t\t" + tojson(chunk.min) + " -->> " + tojson(chunk.max) + " on : " + chunk.shard + " " + tojson(chunk.lastmod)); | |
// }); | |
//} else { | |
// output("\t\t\ttoo many chunksn to print, use verbose if you want to force print"); | |
//} | |
} | |
}); | |
} | |
}); | |
print(raw); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment