Module: check_mk
Branch: master
Commit: 22997661d47cb51070c7fc76e1685c2de33a4f12
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=22997661d47cb5…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Wed Jan 23 14:06:47 2019 +0100
7131 FIX win.mem: Fix incorrect representation of absolute memory levels in graphs
Previously, a warn or crit level of less than e.g. 20 GB free space would be displayed
in the graph as a warn or crit level of more than 20 GB used space.
The problem only affected the levels passed to the metrics system for representation,
not the actual levels used for evaluation.
CMK-1543
Change-Id: Iee645048af2d3f85bd19262224fd310c0ae32268
---
.werks/7131 | 14 +++++++
checks/mem | 49 +++++++++++-----------
.../generictests/datasets/mem_win_regression.py | 4 +-
3 files changed, 41 insertions(+), 26 deletions(-)
diff --git a/.werks/7131 b/.werks/7131
new file mode 100644
index 0000000..eec885d
--- /dev/null
+++ b/.werks/7131
@@ -0,0 +1,14 @@
+Title: win.mem: Fix incorrect representation of absolute memory levels in graphs
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1548248661
+Class: fix
+
+Previously, a warn or crit level of less than e.g. 20 GB free space would be displayed
+in the graph as a warn or crit level of more than 20 GB used space.
+The problem only affected the levels passed to the metrics system for representation,
+not the actual levels used for evaluation.
+
diff --git a/checks/mem b/checks/mem
index be945bb..d5ebd98 100644
--- a/checks/mem
+++ b/checks/mem
@@ -532,6 +532,24 @@ def check_mem_windows(_no_item, params, info):
meminfo = parse_proc_meminfo(info)
now = time.time()
+ def _get_levels_on_used_mb(param_key, total_mb):
+ levels = params.get(param_key)
+ if not isinstance(levels, tuple):
+ # Predictive levels have no level information in the performance data
+ return None, None
+
+ if isinstance(levels[0], float):
+ # float type means percent
+ warn = total_mb * levels[0] / 100
+ else:
+ # int means levels on *free* space
+ warn = total_mb - levels[0]
+ if isinstance(levels[1], float):
+ crit = total_mb * levels[1] / 100
+ else:
+ crit = total_mb - levels[1]
+ return warn, crit
+
for title, prefix, paramname in [("Memory usage", "Mem",
"memory"),
("Commit Charge", "Page",
"pagefile")]:
@@ -546,27 +564,13 @@ def check_mem_windows(_no_item, params, info):
used_mb = total_mb - free_mb
perc = 100.0 * used_kb / total_kb
+ warn, crit = _get_levels_on_used_mb(paramname, total_mb)
+
infotext = "%s: %s (%s/%s)" % (title,
get_percent_human_readable(perc),
get_bytes_human_readable(used_kb * 1024),
get_bytes_human_readable(total_kb * 1024))
- if isinstance(params[paramname], tuple):
- warn, crit = params[paramname]
-
- # In perfdata show warn/crit as absolute values
- # Absolute thresholds are in MB -> transform to MB
- if isinstance(warn, float):
- warn = total_mb * warn / 100
-
- if isinstance(crit, float):
- crit = total_mb * crit / 100
-
- perfdata = [(paramname, used_mb, warn, crit, 0, total_mb)]
-
- # Predictive levels have no level information in the performance data
- else:
- perfdata = [(paramname, used_mb, None, None, 0, total_mb)]
-
+ perfdata = [(paramname, used_mb, warn, crit, 0, total_mb)]
if prefix == "Mem":
perfdata.append(("mem_total", total_mb))
elif prefix == "Page":
@@ -586,15 +590,12 @@ def check_mem_windows(_no_item, params, info):
perfdata.append((paramname + "_avg", used_mb))
# Now check the levels
- if isinstance(params[paramname], tuple):
- if (isinstance(crit, int) and free_mb <= crit) or \
- (isinstance(crit, float) and perc >= crit):
+ if (warn, crit) != (None, None):
+ state = 0
+ if used_mb >= crit:
state = 2
- elif (isinstance(warn, int) and free_mb <= warn) or \
- (isinstance(warn, float) and perc >= warn):
+ elif used_mb >= warn:
state = 1
- else:
- state = 0
# Predictive levels
else:
diff --git a/tests/unit/checks/generictests/datasets/mem_win_regression.py
b/tests/unit/checks/generictests/datasets/mem_win_regression.py
index 601d5e2..86d1460 100644
--- a/tests/unit/checks/generictests/datasets/mem_win_regression.py
+++ b/tests/unit/checks/generictests/datasets/mem_win_regression.py
@@ -32,11 +32,11 @@ checks = {
]),
(None, {'memory': (6553, 3277), 'pagefile': (19492, 77414)}, [
(0, 'Memory usage: 50.0% (15.99 GB/32.00 GB)', [
- ('memory', 16369.96875, 6553, 3277, 0, 32767.48828125),
+ ('memory', 16369.96875, 26214.48828125, 29490.48828125, 0,
32767.48828125),
('mem_total', 32767.48828125, None, None, None, None),
]),
(2, 'Commit Charge: 20.1% (19.04 GB/94.50 GB)', [
- ('pagefile', 19491.90625, 19492.0, 77414.0, 0, 96767.48828125),
+ ('pagefile', 19491.90625, 77275.48828125, 19353.48828125, 0,
96767.48828125),
('pagefile_total', 96767.48828125, None, None, None, None),
]),
]),