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

Unified Diff: modules/nagios/files/check_memory

Issue 4818203867873280: Fixed free memory measurements, cache and buffers are still free memory as far as we are concerned (Closed)
Patch Set: Created Jan. 31, 2014, 10:37 p.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
@@ -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)
)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld