Module: check_mk
Branch: master
Commit: 9f8c194a91278e72f22221ae5896674c5ea1809f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9f8c194a91278e…
Author: Óscar Nájera <on(a)mathias-kettner.de>
Date: Mon Oct 29 14:46:56 2018 +0100
Upperlevels with human readable representation
Change-Id: I56f15451241d68b26fa711abeebbe2c93e4519d7
---
checks/ps.include | 25 ++++++++++++++++---------
tests/unit/checks/test_ps.py | 14 ++++++++++----
2 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/checks/ps.include b/checks/ps.include
index ebb4d1d..9b8b7a2 100644
--- a/checks/ps.include
+++ b/checks/ps.include
@@ -377,7 +377,7 @@ def check_ps_common(item, params, parsed, cpu_cores=1,
info_name="process", tota
yield 0, infotext
-def upperlevels(value, warn, crit):
+def upperlevels(value, warn, crit, readable=str):
infotext = ''
if value >= crit:
state = 2
@@ -386,7 +386,7 @@ def upperlevels(value, warn, crit):
else:
state = 0
if state:
- infotext = ": (warn/crit at %d/%d)" % (warn, crit)
+ infotext = ": (warn/crit at %s/%s)" % tuple(map(readable, (warn,
crit)))
return state, infotext
@@ -432,8 +432,11 @@ def memory_check(processes, params):
infotext = "%s %s" % (get_bytes_human_readable(size * 1024.0), title)
warn_levels, crit_levels = params.get(levels, (None, None))
- state, levelstext = upperlevels(size * 1024, warn_levels,
- crit_levels) if levels in params else (0,
"")
+ if levels in params:
+ state, levelstext = upperlevels(size * 1024, warn_levels, crit_levels,
+ get_bytes_human_readable)
+ else:
+ state, levelstext = 0, ""
yield state, infotext + levelstext, [(metric, size, warn_levels, crit_levels)]
@@ -446,7 +449,8 @@ def memory_perc_check(processes, params, total_ram):
else:
resident_perc = 100 * float(processes.resident_size * 1024) / total_ram
infotext = "%s of total RAM" %
get_percent_human_readable(resident_perc)
- state, levelstext = upperlevels(resident_perc, warn_perc, crit_perc)
+ state, levelstext = upperlevels(resident_perc, warn_perc, crit_perc,
+ get_percent_human_readable)
infotext += levelstext
return state, infotext
@@ -467,8 +471,9 @@ def cpu_check(percent_cpu, item, params):
perf_data.append(("pcpuavg", avg_cpu, warn_cpu, crit_cpu, 0,
params["cpu_average"]))
percent_cpu = avg_cpu # use this for level comparison
- state, levelstext = upperlevels(percent_cpu, warn_cpu,
- crit_cpu) if "cpulevels" in params else (0,
"")
+ state, levelstext = upperlevels(percent_cpu, warn_cpu, crit_cpu,
+ get_percent_human_readable) if "cpulevels"
in params else (0,
+
"")
return state, infotext + levelstext, perf_data
@@ -485,7 +490,8 @@ def individual_process_check(processes, params):
elif the_item.startswith("cpu usage"):
cpu_usage += value
- state, levelstext = upperlevels(cpu_usage, warn_cpu_single, crit_cpu_single)
+ state, levelstext = upperlevels(cpu_usage, warn_cpu_single, crit_cpu_single,
+ get_percent_human_readable)
process_description = name + " with PID %s" % pid if pid else
""
infotext = "%.1f%% CPU for %s%s" % (cpu_usage, process_description,
levelstext)
yield state, infotext
@@ -502,7 +508,8 @@ def uptime_check(times, params):
if "max_age" in params:
warn_age, crit_age = params["max_age"]
- state, levelstext = upperlevels(times.max_elapsed, warn_age, crit_age)
+ state, levelstext = upperlevels(times.max_elapsed, warn_age, crit_age,
+ get_age_human_readable)
infotext += levelstext
return state, infotext
diff --git a/tests/unit/checks/test_ps.py b/tests/unit/checks/test_ps.py
index 3ab750f..99d1b1d 100644
--- a/tests/unit/checks/test_ps.py
+++ b/tests/unit/checks/test_ps.py
@@ -213,6 +213,8 @@ PS_DISCOVERY_WATO_RULES = [
"cpu_average": 15,
"process_info": "html",
"resident_levels_perc": (25.0, 50.0),
+ "virtual_levels": (1024**3, 2*1024**3),
+ "resident_levels": (1024**3, 2*1024**3),
},
"icon": "emacs.png",
"descr": "emacs",
@@ -270,6 +272,8 @@ PS_DISCOVERY_SPECS = [
"cpu_average": 15,
"process_info": "html",
"resident_levels_perc": (25.0, 50.0),
+ "virtual_levels": (1024**3, 2*1024**3),
+ "resident_levels": (1024**3, 2*1024**3),
}),
("cron", "~.*cron", "root", None, {
"max_age": (3600, 7200),
@@ -351,6 +355,8 @@ PS_DISCOVERED_ITEMS = [
"icon": "emacs.png",
"user": "on",
"process_info": "html",
+ "virtual_levels": (1024**3, 2*1024**3),
+ "resident_levels": (1024**3, 2*1024**3),
}),
("firefox is on fire", {
"process": "~.*firefox",
@@ -409,9 +415,9 @@ def test_replace_service_description_exception(check_manager):
check_results = [
CheckResult([
(0, "1 process", [("count", 1, 100000, 100000, 0)]),
- (0, "1.00 GB virtual", [("vsz", 1050360, None, None, None,
None)]),
- (0, "296.14 MB physical", [("rss", 303252, None, None, None,
None)]),
- (1, "28.9% of total RAM: (warn/crit at 25/50)"),
+ (1, "1.00 GB virtual: (warn/crit at 1.00 GB/2.00 GB)",
[("vsz", 1050360, 1073741824, 2147483648, None, None)]),
+ (0, "296.14 MB physical", [("rss", 303252, 1073741824,
2147483648, None, None)]),
+ (1, "28.9% of total RAM: (warn/crit at 25.0%/50.0%)"),
(0, "0.0% CPU (15 min average: 0.0%)", [("pcpu", 0.0, None,
None, None, None),
("pcpuavg", 0.0, None, None, 0,
15)]),
(0, "running for 27 h", []),
@@ -444,7 +450,7 @@ check_results = [
(0, "0.0% CPU for svchost.exe with PID 764"),
(1, "1204 process handles: (warn/crit at 1000/2000)",
[("process_handles", 1204, 1000, 2000,
None, None)]),
- (1, "youngest running for 12.0 s, oldest running for 71 m: (warn/crit at
3600/7200)", []),
+ (1, "youngest running for 12.0 s, oldest running for 71 m: (warn/crit at 60
m/120 m)", []),
]),
CheckResult([
(0, "1 process", [("count", 1, 100000, 100000, 0, None)]),