| 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 |