Created
June 8, 2012 18:58
-
-
Save loopj/2897572 to your computer and use it in GitHub Desktop.
Useful Mongo Shell Functions
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 getCurrentOpStats() { | |
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]); | |
}; | |
} | |
function killLongRunningOps(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"]) | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment