From 539d30700326ce07007870638c4b3d1273df1233 Mon Sep 17 00:00:00 2001 From: Dave Pedu Date: Sun, 6 Dec 2015 23:18:31 -0800 Subject: [PATCH] Handle 0 swap --- pymonitor/monitors/meminfo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymonitor/monitors/meminfo.py b/pymonitor/monitors/meminfo.py index 81a0784..244bc0b 100644 --- a/pymonitor/monitors/meminfo.py +++ b/pymonitor/monitors/meminfo.py @@ -7,8 +7,8 @@ computed_fields = { "mempctfree": lambda items: 1-round((items["memtotal"]-items["memfree"])/items["memtotal"], 2), "mempctused_nocache": lambda items: round((items["memtotal"]-items["memfree"]-items["cached"])/items["memtotal"], 2), "mempctfree_nocache": lambda items: 1-round((items["memtotal"]-items["memfree"]-items["cached"])/items["memtotal"], 2), - "swappctused": lambda items: round((items["swaptotal"]-items["swapfree"])/items["swaptotal"], 2), - "swappctfree": lambda items: 1-round((items["swaptotal"]-items["swapfree"])/items["swaptotal"], 2) + "swappctused": lambda items: round((items["swaptotal"]-items["swapfree"])/items["swaptotal"] if items["swaptotal"] > 0 else 0, 2), + "swappctfree": lambda items: 1-round((items["swaptotal"]-items["swapfree"])/items["swaptotal"] if items["swaptotal"] > 0 else 0, 2) } def meminfo(whitelist=[]):