diff options
-rwxr-xr-x | plugins/memory.py | 17 | ||||
-rw-r--r-- | tests/test_memory.py | 8 | ||||
-rw-r--r-- | tests/test_memory_dataFile.py | 12 |
3 files changed, 18 insertions, 19 deletions
diff --git a/plugins/memory.py b/plugins/memory.py index 6c1de22..5d87da1 100755 --- a/plugins/memory.py +++ b/plugins/memory.py @@ -55,12 +55,13 @@ def showMemStat(warning, critical, s): crit_value = (totalMem * critical) / 100 war_value = (totalMem * warning) / 100 - if utils.convertSize(int(s['memory']['memused']), - "KB", "GB") >= crit_value: + usedMem = utils.convertSize(int(s['memory']['memused']) - int( + s['memory']['cached']), "KB", "GB") + usedPercent = usedMem * 100.0 / totalMem + if usedMem >= crit_value: pl_op["message"] = utils.PluginStatus.CRITICAL pl_op['exit_status'] = utils.PluginStatusCode.CRITICAL - elif utils.convertSize(int(s['memory']['memused']), - "KB", "GB") >= war_value: + elif usedMem >= war_value: pl_op["message"] = utils.PluginStatus.WARNING pl_op['exit_status'] = utils.PluginStatusCode.WARNING else: @@ -71,16 +72,14 @@ def showMemStat(warning, critical, s): "Total=%.2fGB;%.2f;%.2f;0;%.2f" " Used=%.2fGB Buffered=%.2fGB" " Cached=%.2fGB" % ( - float(s['memory']['memused-percent']), - utils.convertSize(int(s['memory']['memused']), - "KB", "GB"), + usedPercent, + usedMem, totalMem, totalMem, war_value, crit_value, totalMem, - utils.convertSize(int(s['memory']['memused']), - "KB", "GB"), + usedMem, utils.convertSize(int(s['memory']['buffers']), "KB", "GB"), utils.convertSize(int(s['memory']['cached']), diff --git a/tests/test_memory.py b/tests/test_memory.py index fb02b5b..f7f67d5 100644 --- a/tests/test_memory.py +++ b/tests/test_memory.py @@ -50,8 +50,8 @@ class memoryTests(TestCaseBase): ) def _showMemStatus_warning_test(self): - w = 40 - c = 60 + w = 20 + c = 30 actual = memory.showMemStat( w, c, test_memory_dataFile.SHOW_MEMORY_STATUS_WARNING_IP @@ -62,8 +62,8 @@ class memoryTests(TestCaseBase): ) def _showMemStatus_critical_test(self): - w = 30 - c = 40 + w = 10 + c = 20 actual = memory.showMemStat( w, c, test_memory_dataFile.SHOW_MEMORY_STATUS_CRITICAL_IP diff --git a/tests/test_memory_dataFile.py b/tests/test_memory_dataFile.py index 679aa17..798cb86 100644 --- a/tests/test_memory_dataFile.py +++ b/tests/test_memory_dataFile.py @@ -35,8 +35,8 @@ SHOW_MEMORY_STATUS_OK_IP = \ 'buffers': '376704', 'dirty': '1696'}} SHOW_MEMORY_STATUS_OK_OP = \ - {'message': "OK- 46.97% used(3.53GB out of 7.51GB)|" - "Total=7.51GB;4.50;5.25;0;7.51 Used=3.53GB " + {'message': "OK- 27.66% used(2.08GB out of 7.51GB)|" + "Total=7.51GB;4.50;5.25;0;7.51 Used=2.08GB " "Buffered=0.36GB Cached=1.45GB", 'exit_status': 0} SHOW_MEMORY_STATUS_WARNING_IP = \ @@ -52,8 +52,8 @@ SHOW_MEMORY_STATUS_WARNING_IP = \ 'buffers': '376704', 'dirty': '1696'}} SHOW_MEMORY_STATUS_WARNING_OP = \ - {'message': "WARNING- 46.97% used(3.53GB out of 7.51GB)" - "|Total=7.51GB;3.00;4.50;0;7.51 Used=3.53GB" + {'message': "WARNING- 27.66% used(2.08GB out of 7.51GB)" + "|Total=7.51GB;1.50;2.25;0;7.51 Used=2.08GB" " Buffered=0.36GB Cached=1.45GB", 'exit_status': 1} SHOW_MEMORY_STATUS_CRITICAL_IP = \ @@ -69,8 +69,8 @@ SHOW_MEMORY_STATUS_CRITICAL_IP = \ 'buffers': '376704', 'dirty': '1696'}} SHOW_MEMORY_STATUS_CRITICAL_OP = \ - {'message': "CRITICAL- 46.97% used(3.53GB out of 7.51GB)|" - "Total=7.51GB;2.25;3.00;0;7.51 Used=3.53GB " + {'message': "CRITICAL- 27.66% used(2.08GB out of 7.51GB)|" + "Total=7.51GB;0.75;1.50;0;7.51 Used=2.08GB " "Buffered=0.36GB Cached=1.45GB", 'exit_status': 2} SHOW_MEMORY_STATUS_EXCEPTION_IP = \ |