erh/mongo-munin

mongo_lock throws an error

Opened this issue · 4 comments

I am running mongo 2.4.8, and with the latest code from this repo, I get a key error when running the mongo_lock plugin:

$ ./mongo_lock
Traceback (most recent call last):
File "./mongo_lock", line 54, in
doData()
File "./mongo_lock", line 34, in doData
print name + ".value " + str( 100 * getServerStatus()["globalLock"]["ratio"] )
KeyError: 'ratio'

@ebeyrent I've forked this some time ago, merged in some of the other forks and added some more stuff. Can't guarantee I'll keep developing on it, but feel free to have a look :-p

Seems to be easy to solve.
The command "curl http://127.0.0.1:28017/_status" doesn't return any "ratio" in "globalLock" variable, but returns lockTime and totalTime. The ratio (I think that this is the question) is lock/total. The only change is in the doData() function below.

def doData():
lock = getServerStatus()["globalLock"]["lockTime"]
total = getServerStatus()["globalLock"]["totalTime"]
print name + ".value " + str( 100.000 * lock / total)

I will send a pull request soon.
Best regards,

Just a quick patch for the similar issue. It just happened that we got these plugins on mongo router, which has mongos process and does not return indexCounters on db.serverStatus() call:

OLD:
def get():
return getServerStatus()["indexCounters"]

NEW:
def get():
if getServerStatus()["process"] == "mongos":
print "This is mongo router. Please use this script on mongod servers ONLY"
exit()
return 0