Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: modules/nagios/files/check_memory

Issue 11773028: Added connections and memory monitoring (Closed)
Patch Set: Addressed comments Created Nov. 4, 2013, 7:53 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: modules/nagios/files/check_memory
===================================================================
--- a/modules/nagios/files/check_memory
+++ b/modules/nagios/files/check_memory
@@ -1,21 +1,28 @@
#!/usr/bin/env python
-import re
+import re, argparse
def format_memory(bytes):
- if bytes >= 1024*1024:
+ if bytes >= 1024 * 1024:
return "%i MB" % (bytes / (1024 * 1024))
elif bytes >= 1024:
return "%i kB" % (bytes / 1024)
else:
return "%i bytes"
if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description="Determine the amount of available memory")
+ parser.add_argument("--physical-warn", dest="memwarn", type=int, default=-1, help="Warning threshold for available physical memory (in percent)")
+ parser.add_argument("--physical-critical", dest="memcrit", type=int, default=-1, help="Critical threshold for available physical memory (in percent)")
+ parser.add_argument("--swap-warn", dest="swapwarn", type=int, default=-1, help="Warning threshold for available swap memory (in percent)")
+ parser.add_argument("--swap-critical", dest="swapcrit", type=int, default=-1, help="Critical threshold for available swap memory (in percent)")
+ args = parser.parse_args()
+
memtotal = None
memfree = None
swaptotal = None
swapfree = None
with open("/proc/meminfo", "r") as file:
for line in file:
label, value = line.split(None, 1)
@@ -43,13 +50,21 @@ if __name__ == "__main__":
mempercentage = round(float(memfree) / memtotal * 100)
swappercentage = round(float(swapfree) / swaptotal * 100)
status = "memory %i%% (%s/%s) swap %i%% (%s/%s)" % (
mempercentage, format_memory(memfree), format_memory(memtotal),
swappercentage, format_memory(swapfree), format_memory(swaptotal)
)
- perfdata = "memory=%i swap=%i" % (mempercentage, swappercentage)
+ perfdata = "memory=%i;%i;%i swap=%i;%i;%i" % (
+ mempercentage, args.memwarn, args.memcrit,
+ swappercentage, args.swapwarn, args.swapcrit
+ )
output = "%s|%s" % (status, perfdata)
- print "OK - " + output
+ if mempercentage <= args.memcrit or swappercentage <= args.swapcrit:
+ print "CRITICAL - " + output
+ elif mempercentage <= args.memwarn or swappercentage <= args.swapwarn:
+ print "WARNING - " + output
+ else:
+ print "OK - " + output
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld