-
-
Save g761007/b7cfe05dbc67fdb76aab 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
DB.prototype.getCurrentOpStats = function() { | |
intervals = [1,5,10,30] | |
waitingForLock = 0; | |
secsRunningStats = {}; | |
inProg = db.currentOp()["inprog"] | |
inProg.forEach(function (op) { | |
if(op["waitingForLock"]) { | |
waitingForLock += 1; | |
} | |
if(op["secs_running"]) { | |
intervals.forEach(function (interval) { | |
if(op["secs_running"] > interval) { | |
secsRunningStats[interval] = secsRunningStats[interval] || 0; | |
secsRunningStats[interval] += 1; | |
} | |
}); | |
} | |
}); | |
print("total = " + inProg.length); | |
print("waitingForLock = " + waitingForLock); | |
for(var i in secsRunningStats) { | |
print("secs_running > " + i + " = " + secsRunningStats[i]); | |
}; | |
} | |
DB.prototype.killLongRunningOps = function(time) { | |
db.currentOp()["inprog"].forEach(function (op) { | |
if(op["secs_running"]) { | |
if(op["secs_running"] > time) { | |
print("Killing this op (running " + op["secs_running"] + " seconds)"); | |
print(tojson(op)) | |
print("") | |
db.killOp(op["opid"]) | |
} | |
} | |
}); | |
} | |
DB.prototype.getLongRunningOps = function(time) { | |
time = time || 30; | |
print("\noperations running longer than " + time + " seconds:\n"); | |
db.currentOp()["inprog"].forEach(function (op) { | |
if(op["secs_running"]) { | |
if(op["secs_running"] > time) { | |
print("op '" + op["opid"] + "' running: " + op["secs_running"] + " seconds (" + parseInt(op["secs_running"]/60) + " minutes)"); | |
print(tojson(op)); | |
} | |
} | |
}); | |
} | |
DB.prototype.totalIndexInfo = function() { | |
var collections = db.getCollectionNames(); | |
print("TOTAL INDEX SIZES:"); | |
var results = [] | |
for (col in collections) { | |
results.push([collections[col], Math.round(db[collections[col]].totalIndexSize() / 1024 / 1024)]); | |
} | |
results = results.sort(function(a, b) { | |
return b[1] - a[1]; | |
}); | |
for (res in results) { | |
print(results[res][0] + ": " + results[res][1] + " MB"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment