Module: check_mk
Branch: master
Commit: e0f1a3b6ba2f4c1208b4eedfca6054dfe6b0ba8e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e0f1a3b6ba2f4c…
Author: Florian Kromer <fk(a)mathias-kettner.de>
Date: Thu Nov 22 14:05:47 2018 +0100
6896 diskstat: Allow configuration of disk io operations
This werk adds support for the configuration of disk io
operation values in rule "Levels for disk IO".
CMK-1285
Change-Id: I4c414ecaa178f91fb0313e215ae9bf75d58e6794
---
.werks/6896 | 13 +++
checks/diskstat.include | 33 ++++++++
cmk/gui/plugins/wato/check_parameters/unsorted.py | 4 +
tests/unit/checks/test_diskstat.py | 98 +++++++++++++++++++++++
4 files changed, 148 insertions(+)
diff --git a/.werks/6896 b/.werks/6896
new file mode 100644
index 0000000..84caadf
--- /dev/null
+++ b/.werks/6896
@@ -0,0 +1,13 @@
+Title: diskstat: Allow configuration of disk io operations
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1542891708
+Class: feature
+
+This werk adds support for the configuration of disk io
+operation values in rule "Levels for disk IO".
+
+CMK-1285
diff --git a/checks/diskstat.include b/checks/diskstat.include
index 569ec35..bfcd82d 100644
--- a/checks/diskstat.include
+++ b/checks/diskstat.include
@@ -156,6 +156,26 @@ def check_diskstat_line(this_time, item, params, line,
mode='sectors'):
ios_per_sec = None
if len(line) >= 6 and line[4] >= 0 and line[5] > 0:
reads, writes = map(int, line[4:6])
+ if "read_ios" in params:
+ warn, crit = params["read_ios"]
+ if reads >= crit:
+ infos.append('Read operations: %d (!!)' % (reads))
+ status = 2
+ elif reads >= warn:
+ infos.append('Read operations: %d (!)' % (reads))
+ status = max(status, 1)
+ else:
+ warn, crit = None, None
+ if "write_ios" in params:
+ warn, crit = params["write_ios"]
+ if writes >= crit:
+ infos.append('Write operations: %d (!!)' % (writes))
+ status = 2
+ elif writes >= warn:
+ infos.append('Write operations: %d (!)' % (writes))
+ status = max(status, 1)
+ else:
+ warn, crit = None, None
ios = reads + writes
ios_per_sec = get_rate(countername + ".ios", this_time, ios)
infos.append("IOs: %.2f/sec" % ios_per_sec)
@@ -467,6 +487,19 @@ def check_diskstat_dict(item, params, disks):
yield check_levels(
ql, what, params.get(what), statemarkers=False, infoname="Average
%s" % plugin_text)
+ # I/O operations
+ for what in "read", "write":
+ if what + "_ios" in disk:
+ ios = disk.pop(what + "_ios")
+ yield check_levels(
+ ios,
+ "disk_" + what + "_ios",
+ params.get(what + "_ios"),
+ unit="1/s",
+ statemarkers=False,
+ infoname="%s operations" % what.title(),
+ )
+
# All the other metrics are currently not output in the plugin output - simply
because
# of their amount. They are present as performance data and will shown in graphs.
diff --git a/cmk/gui/plugins/wato/check_parameters/unsorted.py
b/cmk/gui/plugins/wato/check_parameters/unsorted.py
index a6b4a96..ed2ac49 100644
--- a/cmk/gui/plugins/wato/check_parameters/unsorted.py
+++ b/cmk/gui/plugins/wato/check_parameters/unsorted.py
@@ -11692,6 +11692,10 @@ register_check_parameters(
"introduce a loss of accuracy in your graphs. "),
default_value=300,
)),
+ ("read_ios",
+ Levels(title=_("Read operations"), unit=_("1/s"),
default_levels=(400.0, 600.0))),
+ ("write_ios",
+ Levels(title=_("Write operations"), unit=_("1/s"),
default_levels=(300.0, 400.0))),
]),
TextAscii(
title=_("Device"),
diff --git a/tests/unit/checks/test_diskstat.py b/tests/unit/checks/test_diskstat.py
new file mode 100644
index 0000000..6cefc22
--- /dev/null
+++ b/tests/unit/checks/test_diskstat.py
@@ -0,0 +1,98 @@
+import pytest
+
+from checktestlib import CheckResult, assertCheckResultsEqual
+
+pytestmark = pytest.mark.checks
+
+
+(a)pytest.mark.parametrize("item;item, params, disks, expected", [
+ ("sda", {
+ 'average': 0.0,
+ 'read_ios': (200.0, 300.0),
+ 'write_ios': (400.0, 500.0),
+ 'latency': 0.0,
+ 'latency_perfdata': 0.0,
+ 'read_ql': 0.0,
+ 'write_ql': 0.0,
+ 'ql_perfdata': 0.0,
+ }, {
+ "sda": {
+ 'node': 'node_name',
+ 'read_ios': 201.0,
+ 'write_ios': 401.0,
+ 'read_throughput': 0.0,
+ 'write_throughput': 0.0,
+ 'utilization': 0.0,
+ 'latency': 0.0,
+ 'average_request_size': 0.0,
+ 'average_wait': 0.0,
+ 'average_read_wait': 0.0,
+ 'average_read_request_size': 0.0,
+ 'average_write_wait': 0.0,
+ 'average_write_request_size': 0.0,
+ 'queue_length': 0.0,
+ }
+ }, [(0, 'Utilization: 0.00 %', [('disk_utilization', 0.0)]),
+ (0, 'Read: 0.00 B/s', [('disk_read_throughput', 0.0)]),
+ (0, 'Write: 0.00 B/s', [('disk_write_throughput', 0.0)]),
+ (0, 'Average Wait: 0.00 ms', [('wait', 0.0)]),
+ (0, 'Average Read Wait: 0.00 ms', [('read_wait', 0.0)]),
+ (0, 'Average Write Wait: 0.00 ms', [('write_wait', 0.0)]),
+ (0, 'Latency: 0.00 ms', [('disk_latency', 0.0)]),
+ (0, 'Average Queue Length: 0.00', [('queue_length', 0.0)]),
+ (1, 'Read operations: 201.00 1/s (warn/crit at 200.00 1/s/300.00 1/s)',
+ [('disk_read_ios', 201.0, 200.0, 300.0)]),
+ (1, 'Write operations: 401.00 1/s (warn/crit at 400.00 1/s/500.00 1/s)',
+ [('disk_write_ios', 401.0, 400.0, 500.0)]),
+ (0, '', [('disk_average_read_request_size', 0.0),
('disk_average_request_size', 0.0),
+ ('disk_average_write_request_size', 0.0)])]),
+ ("sda", {
+ 'average': 0.0,
+ 'read_ios': (200.0, 300.0),
+ 'write_ios': (400.0, 500.0),
+ 'latency': 0.0,
+ 'latency_perfdata': 0.0,
+ 'read_ql': 0.0,
+ 'write_ql': 0.0,
+ 'ql_perfdata': 0.0,
+ }, {
+ "sda": {
+ 'node': 'node_name',
+ 'read_ios': 301.0,
+ 'write_ios': 501.0,
+ 'read_throughput': 0.0,
+ 'write_throughput': 0.0,
+ 'utilization': 0.0,
+ 'latency': 0.0,
+ 'average_request_size': 0.0,
+ 'average_wait': 0.0,
+ 'average_read_wait': 0.0,
+ 'average_read_request_size': 0.0,
+ 'average_write_wait': 0.0,
+ 'average_write_request_size': 0.0,
+ 'queue_length': 0.0,
+ }
+ }, [(0, 'Utilization: 0.00 %', [('disk_utilization', 0.0)]),
+ (0, 'Read: 0.00 B/s', [('disk_read_throughput', 0.0)]),
+ (0, 'Write: 0.00 B/s', [('disk_write_throughput', 0.0)]),
+ (0, 'Average Wait: 0.00 ms', [('wait', 0.0)]),
+ (0, 'Average Read Wait: 0.00 ms', [('read_wait', 0.0)]),
+ (0, 'Average Write Wait: 0.00 ms', [('write_wait', 0.0)]),
+ (0, 'Latency: 0.00 ms', [('disk_latency', 0.0)]),
+ (0, 'Average Queue Length: 0.00', [('queue_length', 0.0)]),
+ (2, 'Read operations: 301.00 1/s (warn/crit at 200.00 1/s/300.00 1/s)',
+ [('disk_read_ios', 301.0, 200.0, 300.0)]),
+ (2, 'Write operations: 501.00 1/s (warn/crit at 400.00 1/s/500.00 1/s)',
+ [('disk_write_ios', 501.0, 400.0, 500.0)]),
+ (0, '', [('disk_average_read_request_size', 0.0),
('disk_average_request_size', 0.0),
+ ('disk_average_write_request_size', 0.0)])])
+])
+def test_diskstat_dict_warns_and_crits_about_read_and_write_ios(check_manager, item,
params, disks,
+ expected, monkeypatch):
+ check = check_manager.get_check("diskstat")
+ check_diskstat_dict = check.context["check_diskstat_dict"]
+ with monkeypatch.context() as m:
+ m.setattr('time.time', lambda: 0.0)
+ actual_result = CheckResult(check_diskstat_dict(item, params, disks))
+ expected_result = CheckResult(expected)
+ assertCheckResultsEqual(actual_result, expected_result)