Module: check_mk
Branch: master
Commit: da8c7907833b58fca780e2e0708bd02a0f583756
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=da8c7907833b58…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Wed Jan 9 11:57:22 2019 +0100
6951 vms_cpu: Levels for utilization
Levels and averaging can now be configured for the utilization.
Change-Id: I94443f5b6b63a83dabafaa99e42b6c178ae80396
---
.werks/6951 | 10 ++++
checkman/vms_cpu | 4 +-
checks/vms_cpu | 64 ++++++++++++----------
.../generictests/datasets/vms_cpu_regression.py | 26 +++++----
4 files changed, 63 insertions(+), 41 deletions(-)
diff --git a/.werks/6951 b/.werks/6951
new file mode 100644
index 0000000..57d4e55
--- /dev/null
+++ b/.werks/6951
@@ -0,0 +1,10 @@
+Title: vms_cpu: Levels for utilization
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1547031355
+Class: feature
+
+Levels and averaging can now be configured for the utilization.
diff --git a/checkman/vms_cpu b/checkman/vms_cpu
index 9901faf..1cf28b3 100644
--- a/checkman/vms_cpu
+++ b/checkman/vms_cpu
@@ -6,9 +6,9 @@ distribution: check_mk
description:
Check CPU utilization (user, system, idle) and IO-Wait on an
OpenVMS system. The number of CPUs is taken into account so that
- maximum percentage is 100% is refers to the total CPUs available.
+ maximum percentage is 100% and refers to the total CPUs available.
- A level can be set only on {wait} (disk wait).
+ Levels can be set only on {wait} (disk wait) and the utilization.
inventory:
One check per host is created for OpenVMS systems.
diff --git a/checks/vms_cpu b/checks/vms_cpu
index a7e2bfb..f32dfa4 100644
--- a/checks/vms_cpu
+++ b/checks/vms_cpu
@@ -24,51 +24,57 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-vms_cpu_default_levels = None
-
# Example output from agent:
# <<<vms_cpu>>>
# 1 99.17 0.54 0.18 0.00
+def parse_vms_cpu(info):
+ parsed = {}
+ try:
+ parsed['num_cpus'] = int(info[0][0])
+ for i, key in enumerate(('idle', 'user',
'wait_interrupt', 'wait_npsync'), 1):
+ parsed[key] = float(info[0][i]) / parsed['num_cpus']
+ except (IndexError, ValueError):
+ return {}
+
+ return parsed
+
+
def inventory_vms_cpu(info):
- if len(info) > 0:
- return [(None, "vms_cpu_default_levels")]
+ if info:
+ yield None, {}
-def check_vms_cpu(item, params, info):
- num_cpus = int(info[0][0])
- idle, user, wait_interrupt, wait_npsync = [float(x) / num_cpus for x in info[0][1:]]
- wait = wait_interrupt + wait_npsync
- system = 100.0 - idle - user - wait
- infotext = "user: %2.1f%%, system: %2.1f%%, wait: %2.1f%%" % (user, system,
wait)
- state = 0
- perfdata = [
- ("user", user),
- ("system", system),
- ("wait", wait, 0, 0),
- ]
+def check_vms_cpu(_no_item, params, parsed):
+ # ancient tuple rule
+ # and legacy default None prior to 1.6
params = transform_cpu_iowait(params)
- if isinstance(params.get('iowait'), tuple):
- warn, crit = params['iowait']
- perfdata = [
- ("user", user),
- ("system", system),
- ("wait", wait, warn, crit),
- ]
- if wait >= crit:
- state = 2
- elif wait >= warn:
- state = 1
- return (state, infotext, perfdata)
+ user = parsed["user"]
+ wait = parsed["wait_interrupt"] + parsed["wait_npsync"]
+ util = 100. - parsed["idle"]
+ system = util - user - wait
+
+ yield check_levels(user, "user", None, '%')
+ yield check_levels(system, "system", None, '%')
+ yield check_levels(wait, "wait", params.get("iowait"),
'%')
+
+ for util_result in check_cpu_util(util, params):
+ yield util_result
+
+ num_cpus = parsed['num_cpus']
+ unit = "CPU" if num_cpus == 1 else "CPUs"
+ yield check_levels(
+ num_cpus, 'cpu_entitlement', None, unit=unit, infoname="100%
corresponding to")
check_info['vms_cpu'] = {
+ "parse_function": parse_vms_cpu,
"check_function": check_vms_cpu,
"inventory_function": inventory_vms_cpu,
"service_description": "CPU utilization",
"has_perfdata": True,
"group": "cpu_iowait",
- 'includes': ['transforms.include'],
+ "includes": ["transforms.include",
"cpu_util.include"],
}
diff --git a/tests/unit/checks/generictests/datasets/vms_cpu_regression.py
b/tests/unit/checks/generictests/datasets/vms_cpu_regression.py
index e2a78fa..6c48503 100644
--- a/tests/unit/checks/generictests/datasets/vms_cpu_regression.py
+++ b/tests/unit/checks/generictests/datasets/vms_cpu_regression.py
@@ -2,17 +2,23 @@ checkname = 'vms_cpu'
info = [['1', '99.17', '0.54', '0.18', '0.00']]
-discovery = {'': [(None, 'vms_cpu_default_levels')]}
+discovery = {'': [(None, {})]}
checks = {
'': [
- (None, None, [(0, 'user: 0.5%, system: 0.1%, wait: 0.2%',
- [('user', 0.54, None, None, None, None),
- ('system', 0.10999999999999827, None, None, None, None),
- ('wait', 0.18, 0, 0, None, None)])]),
- (None, (0.1, 0.5), [(1, 'user: 0.5%, system: 0.1%, wait: 0.2%',
- [('user', 0.54, None, None, None, None),
- ('system', 0.10999999999999827, None, None, None,
None),
- ('wait', 0.18, 0.1, 0.5, None, None)])]),
- ]
+ (None, None, [
+ (0, 'user: 0.54%', [('user', 0.54)]),
+ (0, 'system: 0.11%', [('system', 0.10999999999999827)]),
+ (0, 'wait: 0.18%', [('wait', 0.18)]),
+ (0, 'total cpu: 0.83%', [('util', 0.8299999999999983, None,
None, 0, 100)]),
+ (0, "100% corresponding to: 1.00 CPU", [('cpu_entitlement',
1)]),
+ ]),
+ (None, (0.1, 0.5), [
+ (0, 'user: 0.54%', [('user', 0.54)]),
+ (0, 'system: 0.11%', [('system', 0.10999999999999827)]),
+ (1, 'wait: 0.18% (warn/crit at 0.10%/0.50%)', [('wait', 0.18,
0.1, 0.5)]),
+ (0, 'total cpu: 0.83%', [('util', 0.8299999999999983, None,
None, 0, 100)]),
+ (0, "100% corresponding to: 1.00 CPU", [('cpu_entitlement',
1)]),
+ ]),
+ ],
}