Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
check_mongodb: Updating to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
waja committed Mar 5, 2015
1 parent 5874628 commit 6ed8e1b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
29 changes: 25 additions & 4 deletions check_mongodb/check_mongodb.py
Expand Up @@ -16,6 +16,8 @@
# - @jbraeuer on github
# - Dag Stockstad <dag.stockstad@gmail.com>
# - @Andor on github
# - Steven Richards - Captainkrtek on github
# - Max Vernimmen
#
# USAGE
#
Expand Down Expand Up @@ -375,7 +377,7 @@ def check_rep_lag(con, host, port, warning, critical, percent, perf_data, max_la
for member in rs_status["members"]:
if member["stateStr"] == "PRIMARY":
primary_node = member
if member["name"].split(':')[0] == host and int(member["name"].split(':')[1]) == port:
if member.get('self') == True:
host_node = member

# Check if we're in the middle of an election and don't have a primary
Expand Down Expand Up @@ -501,8 +503,22 @@ def check_memory(con, warning, critical, perf_data, mapped_memory):
#
# These thresholds are basically meaningless, and must be customized to your system's ram
#
warning = warning or 8
critical = critical or 16

# Get the total system merory and calculate based on that how much memory used by Mongodb is ok or not.
meminfo = open('/proc/meminfo').read()
matched = re.search(r'^MemTotal:\s+(\d+)', meminfo)
if matched:
mem_total_kB = int(matched.groups()[0])

# Old way
#critical = critical or 16
# The new way. if using >80% then warn, if >90% then critical level
warning = warning or (mem_total_kB * 0.8) / 1024.0 / 1024.0
critical = critical or (mem_total_kB * 0.9) / 1024.0 / 1024.0

# debugging
#print "mem total: {0}kb, warn: {1}GB, crit: {2}GB".format(mem_total_kB,warning, critical)

try:
data = get_server_status(con)
if not data['mem']['supported'] and not mapped_memory:
Expand Down Expand Up @@ -593,7 +609,12 @@ def check_lock(con, warning, critical, perf_data):
#
# calculate percentage
#
lock_percentage = float(data['globalLock']['lockTime']) / float(data['globalLock']['totalTime']) * 100
lockTime = data['globalLock']['lockTime']
totalTime = data['globalLock']['totalTime']
if lockTime > totalTime:
lock_percentage = 0.00
else:
lock_percentage = float(lockTime) / float(totalTime) * 100
message = "Lock Percentage: %.2f%%" % lock_percentage
message += performance_data(perf_data, [("%.2f" % lock_percentage, "lock_percentage", warning, critical)])
return check_levels(lock_percentage, warning, critical, message)
Expand Down
2 changes: 1 addition & 1 deletion check_mongodb/control
@@ -1,6 +1,6 @@
Uploaders: Jan Wagner <waja@cyconet.org>
Recommends: python-pymongo
Version: 60b639ef4c
Version: 2032d64ba1
Homepage: https://github.com/mzupan/nagios-plugin-mongodb
Watch: https://github.com/mzupan/nagios-plugin-mongodb <span class="sha">([0-9a-f]+)</span>
Description: Plugin script to monitor your MongoDB server(s)
2 changes: 1 addition & 1 deletion debian/control
Expand Up @@ -98,7 +98,7 @@ Description: Plugins for nagios compatible monitoring systems
This plugin excludes the system cache and buffer, because
on some system with very stable memory usage it is perfectly
normal for system cache to fill in all available memory.
* check_mongodb (60b639ef4c): Plugin script to monitor your MongoDB server(s)
* check_mongodb (2032d64ba1): Plugin script to monitor your MongoDB server(s)
* check_multipath (0.2.1): plugin to monitor the number of available and
failed paths of multipath devices
* check_mysql_health (2.1.8.2): plugin to check various parameters of a
Expand Down

0 comments on commit 6ed8e1b

Please sign in to comment.