Created
October 2, 2012 15:25
-
-
Save mpobrien/3820112 to your computer and use it in GitHub Desktop.
healthchecker
This file contains hidden or 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 collectDataForCluster(seed){ | |
var connection = new Mongo(seed); | |
var configDb = connection.getDB("config") | |
var shards = configDb.shards.find().toArray() | |
var shardData = {} | |
for(var i=0;i<shards.length;i++){ | |
var shardHosts = shards[i].host; | |
var slashIndex = shardHosts.indexOf("/") | |
if(slashIndex >=0){ | |
replSetName = shardHosts.substring(0, slashIndex); | |
hosts = shardHosts.substring(slashIndex+1).split(",") | |
shardId = shards[i]._id | |
shardData[shardId] = collectDataForReplicaSet(hosts[0]) | |
shardData[shardId].shardHosts = shardHosts | |
}else{ | |
shardId = shards[i]._id | |
shardData[shardId] = collectDataForHost(shardHosts) | |
shardData[shardId].shardHosts = shardHosts | |
} | |
} | |
return shardData; | |
} | |
function collectDataForReplicaSet(seed){ | |
var connection = new Mongo(seed); | |
connection.setSlaveOk(true); | |
var adminDb = connection.getDB("admin") | |
hosts = adminDb.isMaster().hosts; | |
printjson(hosts); | |
replicaSetData = {} | |
replicaSetData.conf = connection.getDB("local").system.replset.findOne(); | |
for(var i=0;i<hosts.length;i++){ | |
print("checking data for " + hosts[i]); | |
hostname = hosts[i] | |
replicaSetData[hostname] = collectDataForHost(hostname); | |
} | |
return replicaSetData | |
} | |
function collectDataForHost(host){ | |
print("collecting data for " + host); | |
hostData = {} | |
connection = new Mongo(host); | |
connection.setSlaveOk(true); | |
admindb = connection.getDB("admin"); | |
hostData.serverStatus = admindb.serverStatus() | |
hostData.buildInfo = admindb.runCommand("buildInfo") | |
hostData.cmdLineOpts = admindb.runCommand("getCmdLineOpts") | |
hostData.params = admindb.runCommand({"getParameter":1, "quiet":1, "syncdelay":1, notablescan:1, logLevel:1, replApplyBatchSize:1}) | |
var dbnames = connection.getDBNames() | |
hostData.dbs = {} | |
//hostData.replSetStatus = admindb.runCommand("replSetGetStatus") | |
for(var i=0;i<dbnames.length;i++){ | |
hostData.dbs[dbnames[i]] = {} | |
var db = connection.getDB(dbnames[i]) | |
hostData.dbs[dbnames[i]].stats = db.stats() | |
var collectionNames = db.getCollectionNames(); | |
hostData.dbs[dbnames[i]].collections = {} | |
for(var j=0;j<collectionNames.length;j++){ | |
var collectionName = collectionNames[j] | |
var collection = db.getCollection(collectionName) | |
hostData.dbs[dbnames[i]].collections[collectionName] = collection.stats() | |
hostData.dbs[dbnames[i]].collections[collectionName].sampleDoc = collection.findOne() | |
} | |
} | |
return hostData | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment