Index: modules/nagios/files/check_memory |
=================================================================== |
--- a/modules/nagios/files/check_memory |
+++ b/modules/nagios/files/check_memory |
@@ -13,44 +13,38 @@ def format_memory(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 |
+ meminfo = {} |
with open("/proc/meminfo", "r") as file: |
for line in file: |
label, value = line.split(None, 1) |
label = label.lower().rstrip(":") |
value = value.strip() |
match = re.match(r"^(\d+)\s+(kb|mb|gb)$", value, re.IGNORECASE) |
if match: |
value = int(match.group(1)) * 1024 |
if match.group(2).lower() != "kb": |
value *= 1024 |
if match.group(2).lower() != "mb": |
value *= 1024 |
else: |
value = int(value) |
+ meminfo[label] = value |
- if label == "memtotal": |
- memtotal = value |
- elif label == "memfree": |
- memfree = value |
- elif label == "swaptotal": |
- swaptotal = value |
- elif label == "swapfree": |
- swapfree = value |
+ memtotal = meminfo.get("memtotal", 0) |
+ memfree = meminfo.get("memfree", 0) + meminfo.get("buffers", 0) + meminfo.get("cached", 0) |
+ swaptotal = meminfo.get("swaptotal", 0) |
+ swapfree = meminfo.get("swapfree", 0) + meminfo.get("swapcached", 0) |
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) |
) |