Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing return and Mongo3 support for index_miss_ratio option #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 31 additions & 26 deletions check_mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def main(argv):
elif action == "last_flush_time":
return check_flushing(con, warning, critical, False, perf_data)
elif action == "index_miss_ratio":
index_miss_ratio(con, warning, critical, perf_data)
return index_miss_ratio(con, warning, critical, perf_data, mongo_version)
elif action == "databases":
return check_databases(con, warning, critical, perf_data)
elif action == "collections":
Expand Down Expand Up @@ -670,34 +670,39 @@ def check_flushing(con, warning, critical, avg, perf_data):
return exit_with_general_critical(e)


def index_miss_ratio(con, warning, critical, perf_data):
def index_miss_ratio(con, warning, critical, perf_data, mongo_version):
warning = warning or 10
critical = critical or 30
try:
data = get_server_status(con)

try:
serverVersion = tuple(con.server_info()['version'].split('.'))
if serverVersion >= tuple("2.4.0".split(".")):
miss_ratio = float(data['indexCounters']['missRatio'])
else:
miss_ratio = float(data['indexCounters']['btree']['missRatio'])
except KeyError:
not_supported_msg = "not supported on this platform"
if data['indexCounters'].has_key('note'):
print "OK - MongoDB says: " + not_supported_msg
return 0
else:
print "WARNING - Can't get counter from MongoDB"
return 1

message = "Miss Ratio: %.2f" % miss_ratio
message += performance_data(perf_data, [("%.2f" % miss_ratio, "index_miss_ratio", warning, critical)])

return check_levels(miss_ratio, warning, critical, message)
if mongo_version == "2":
try:
data = get_server_status(con)

try:
serverVersion = tuple(con.server_info()['version'].split('.'))
if serverVersion >= tuple("2.4.0".split(".")):
miss_ratio = float(data['indexCounters']['missRatio'])
else:
miss_ratio = float(data['indexCounters']['btree']['missRatio'])
except KeyError:
not_supported_msg = "not supported on this platform"
if data['indexCounters'].has_key('note'):
print "OK - MongoDB says: " + not_supported_msg
return 0
else:
print "WARNING - Can't get counter from MongoDB"
return 1

message = "Miss Ratio: %.2f" % miss_ratio
message += performance_data(perf_data, [("%.2f" % miss_ratio, "index_miss_ratio", warning, critical)])

return check_levels(miss_ratio, warning, critical, message)

except Exception, e:
return exit_with_general_critical(e)

except Exception, e:
return exit_with_general_critical(e)
else:
print "FAIL - Mongo version 3.x doesn't report on index miss ratio"
return 1

def check_replset_quorum(con, perf_data):
db = con['admin']
Expand Down