Created
January 27, 2013 20:30
-
-
Save scotthernandez/4650301 to your computer and use it in GitHub Desktop.
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
printShardingStatus = function( configDB , verbose ){ | |
if (configDB === undefined) | |
configDB = db.getSisterDB('config') | |
var version = configDB.getCollection( "version" ).findOne(); | |
if ( version == null ){ | |
print( "printShardingStatus: this db does not have sharding enabled. be sure you are connecting to a mongos from the shell and not to a mongod." ); | |
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().sort( { _id : 1 } ).forEach( | |
function(z){ | |
output( "\t" + tojsononeline( z ) ); | |
} | |
); | |
output( " databases:" ); | |
configDB.databases.find().sort( { name : 1 } ).forEach( | |
function(db){ | |
output( "\t" + tojsononeline(db,"",true) ); | |
if (db.partitioned){ | |
configDB.collections.find( { _id : new RegExp( "^" + | |
RegExp.escape(db._id) + "\\." ) } ). | |
sort( { _id : 1 } ).forEach( function( coll ){ | |
if ( coll.dropped == false ){ | |
output( "\t\t" + coll._id ); | |
output( "\t\t\tshard key: " + tojson(coll.key) ); | |
output( "\t\t\tchunks:" ); | |
res = configDB.chunks.group( { cond : { ns : coll._id } , key : { shard : 1 }, | |
reduce : function( doc , out ){ out.nChunks++; if (doc.jumbo) out.nJumbo++ } , initial : { nChunks : 0, nJumbo : 0 } } ); | |
var totalChunks = 0; | |
res.forEach( function(z){ | |
totalChunks += z.nChunks; | |
output( "\t\t\t\t" + z.shard + "\t" + z.nChunks + "\t" + z.nJumbo ); | |
} ) | |
if ( totalChunks < 20 || 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 ) + " " + | |
( chunk.jumbo ? "jumbo " : "" ) ); | |
} | |
); | |
} | |
else { | |
output( "\t\t\ttoo many chunks to print, use verbose if you want to force print" ); | |
} | |
configDB.tags.find( { ns : coll._id } ).sort( { min : 1 } ).forEach( | |
function( tag ) { | |
output( "\t\t\t tag: " + tag.tag + " " + tojson( tag.min ) + " -->> " + tojson( tag.max ) ); | |
} | |
) | |
} | |
} | |
) | |
} | |
} | |
); | |
print( raw ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment