Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / nfsiostat
blob1a1bd3468ed47fb987b88d02160b9e41c44d8645
1 #!/usr/bin/python
2 # +------------------------------------------------------------------+
3 # | ____ _ _ __ __ _ __ |
4 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
5 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
6 # | | |___| | | | __/ (__| < | | | | . \ |
7 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
8 # | |
9 # | Copyright Mathias Kettner 2018 mk@mathias-kettner.de |
10 # +------------------------------------------------------------------+
12 # This file is part of Check_MK.
13 # The official homepage is at http://mathias-kettner.de/check_mk.
15 # check_mk is free software; you can redistribute it and/or modify it
16 # under the terms of the GNU General Public License as published by
17 # the Free Software Foundation in version 2. check_mk is distributed
18 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
19 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
20 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
21 # tails. You should have received a copy of the GNU General Public
22 # License along with GNU Make; see the file COPYING. If not, write
23 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
24 # Boston, MA 02110-1301 USA.
26 # example output
28 #y.y.y.y:/mount/name mounted on /var/log/da:
30 # op/s rpc bklog
31 #2579.20 0.00
32 #read: ops/s kB/s kB/op retrans avg RTT (ms) avg exe (ms)
33 # 0.000 0.000 0.000 0 (0.0%) 0.000 0.000
34 #write: ops/s kB/s kB/op retrans avg RTT (ms) avg exe (ms)
35 # 2578.200 165768.087 64.296 0 (0.0%) 21.394 13980.817
37 #x.x.x.x:/mount/name mounted on /data:
38 # ...
40 param_name = {
41 "0": ("op_s", "Operations", 1, "%.2f/s"),
42 "1": ("rpc_backlog", "RPC Backlog", 1, "%.2f"),
43 "2": ("read_ops", "Read operations /s", 1, "%.3f/s"),
44 "3": ("read_b_s", "Reads size /s", 1000, "%.3fB/s"),
45 "4": ("read_b_op", "Read bytes per operation", 1000, "%.3fB/op"),
46 "5": ("read_retrans", "Read Retransmission", 1, "%.1f%%"),
47 "6": ("read_retrans", "Read Retransmission", 1, "%.1f%%"),
48 "7": (
49 "read_avg_rtt_ms",
50 "Read average RTT",
51 1000,
52 "%.3f/s",
54 "8": (
55 "read_avg_exe_ms",
56 "Read average EXE",
57 1000,
58 "%.3f/s",
60 "9": ("write_ops_s", "Write operations /s", 1, "%.3f/s"),
61 "10": ("write_b_s", "Writes size /s", 1000, "%.3fkB/s"),
62 "11": ("write_b_op", "Write bytes per operation", 1000, "%.3fB/op"),
63 "12": ("write_retrans", "Write Retransmission", 1, "%.1f%%"),
64 "13": ("write_retrans", "Write Retransmission", 1, "%.3f%%"),
65 "14": ("write_avg_rtt_ms", "Write Average RTT", 1, "%.3f/ms"),
66 "15": ("write_avg_exe_ms", "Write Average EXE", 1, "%.3f/ms"),
70 def parse_nfsiostat(info):
71 #removes double list
72 [new_info] = info
73 import re
74 # Result is a dictionary with mountpoint as key and a list of (currently 16)
75 # metrics. Metrics are in the same order, from left to right, top to bottom,
76 # as in the output of nfsiostat.
77 # The first regex group (m0) identifies the mountpount and the second group
78 # (m1) provides a space separated list of metrics.
79 # Future expandibility or changes to the nfsiostat command will require
80 # at most a re-ordering of these values (in check_nfsiostat_parames) and
81 # changing the check to include new metrics (via swtiches/flags)
82 parsed = {m[0]: m[1:] for m in re.findall(r'(\S+:/\S+)%s' % \
83 (r'.*?([\d.]+)' * 16), str(new_info).strip('[]'), flags=re.DOTALL)}
84 return parsed
87 def inventory_nfsiostat(parsed):
88 for mountname in parsed.keys():
89 yield mountname, {}
92 def check_nfsiostat(item, params, parsed):
93 # check the value we recieved against our map of values
94 # assign appropriate type to value
95 def check_nfsiostat_params(count, value):
96 item = param_name[str(count)][0]
97 title = param_name[str(count)][1]
98 fmt = param_name[str(count)][3]
99 value = float(value)
101 if params:
102 if params.get(item, 0):
103 crit = float(params[item][1])
104 warn = float(params[item][0])
105 if value >= crit:
106 perfdata = [(item, value, warn, crit)]
107 return (2, "%s: %s" % (title, fmt % value), perfdata)
108 elif value >= warn:
109 perfdata = [(item, value, warn, crit)]
110 return (1, "%s: %s" % (title, fmt % value), perfdata)
112 perfdata = [(item, value)]
113 return (0, "%s: %s" % (title, fmt % value), perfdata)
115 for mountpoint, values in parsed.items():
116 # We have duplicate items at index 5 and 12. We exclude the dupes here
117 if mountpoint == item:
118 count = 0
119 for value in values:
120 if count != 5 and count != 12:
121 yield check_nfsiostat_params(count, value)
122 count = count + 1
125 check_info['nfsiostat'] = {
126 'parse_function': parse_nfsiostat,
127 'inventory_function': inventory_nfsiostat,
128 'check_function': check_nfsiostat,
129 'service_description': 'NFS IO stats %s',
130 'group': 'nfsiostat',
131 'has_perfdata': True,