Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / ddn_s2a_stats
blobdab85dcfce7c5f3cc6737bf3a07e11ae16e22650
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2017 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
28 def parse_ddn_s2a_stats(info):
29 parsed = parse_ddn_s2a_api_response(info)
31 for key in parsed:
32 if key.startswith(u"All_ports"):
33 parsed[key] = parsed[key][0]
35 return parsed
38 # .--Read hits-----------------------------------------------------------.
39 # | ____ _ _ _ _ |
40 # | | _ \ ___ __ _ __| | | |__ (_) |_ ___ |
41 # | | |_) / _ \/ _` |/ _` | | '_ \| | __/ __| |
42 # | | _ < __/ (_| | (_| | | | | | | |_\__ \ |
43 # | |_| \_\___|\__,_|\__,_| |_| |_|_|\__|___/ |
44 # | |
45 # '----------------------------------------------------------------------'
47 ddn_s2a_readhits_default_levels = (85.0, 70.0)
50 def inventory_ddn_s2a_stats_readhits(parsed):
51 if u"All_ports_Read_Hits" in parsed:
52 yield "Total", "ddn_s2a_readhits_default_levels"
53 for nr, _ in enumerate(parsed.get(u"Read_Hits", [])):
54 yield "%d" % (nr + 1), "ddn_s2a_readhits_default_levels"
57 def check_ddn_s2a_stats_readhits(item, params, parsed):
59 if item == "Total":
60 read_hits = float(parsed[u"All_ports_Read_Hits"])
61 else:
62 read_hits = float(parsed[u"Read_Hits"][int(item) - 1])
64 infotext = "%.1f%%" % read_hits
65 if params is None:
66 perfdata = [("read_hits", read_hits)] # TODO: Define metric
67 status = 0
68 else:
69 warn, crit = params
70 levelstext = " (warn/crit below %.1f/%.1f%%)" % params
71 perfdata = [("read_hits", read_hits, warn, crit)]
72 if read_hits < crit:
73 status = 2
74 infotext += levelstext
75 elif read_hits < warn:
76 status = 1
77 infotext += levelstext
78 else:
79 status = 0
81 return status, infotext, perfdata
84 check_info["ddn_s2a_stats.readhits"] = {
85 "inventory_function": inventory_ddn_s2a_stats_readhits,
86 "check_function": check_ddn_s2a_stats_readhits,
87 "service_description": "DDN S2A Read Hits %s",
88 "has_perfdata": True,
89 "group": "read_hits",
93 # .--I/O transactions----------------------------------------------------.
94 # | ___ _____ |
95 # | |_ _| / / _ \ |
96 # | | | / / | | | |
97 # | | | / /| |_| | |
98 # | |___/_/ \___/ |
99 # | |
100 # | _ _ _ |
101 # | | |_ _ __ __ _ _ __ ___ __ _ ___| |_(_) ___ _ __ ___ |
102 # | | __| '__/ _` | '_ \/ __|/ _` |/ __| __| |/ _ \| '_ \/ __| |
103 # | | |_| | | (_| | | | \__ \ (_| | (__| |_| | (_) | | | \__ \ |
104 # | \__|_| \__,_|_| |_|___/\__,_|\___|\__|_|\___/|_| |_|___/ |
105 # | |
106 # '----------------------------------------------------------------------'
108 factory_settings["ddn_s2a_stats_io_default_levels"] = {
109 "total": (28000, 33000),
113 def inventory_ddn_s2a_stats_io(parsed):
114 if u"All_ports_Read_IOs" in parsed:
115 yield "Total", {}
116 for nr, _ in enumerate(parsed.get(u"Read_IOs", [])):
117 yield "%d" % (nr + 1), {}
120 def check_ddn_s2a_stats_io(item, params, parsed):
121 def check_io_levels(value, levels, infotext_formatstring, perfname=None):
122 infotext = infotext_formatstring % value
123 if levels is None:
124 perfdata = [(perfname, value)]
125 status = 0
126 else:
127 warn, crit = levels
128 perfdata = [(perfname, value, warn, crit)]
129 levelstext = " (warn/crit at %.2f/%.2f 1/s)" % (warn, crit)
130 if value >= crit:
131 status = 2
132 infotext += levelstext
133 elif value >= warn:
134 status = 1
135 infotext += levelstext
136 else:
137 status = 0
139 if perfname is None:
140 return status, infotext
141 return status, infotext, perfdata
143 if item == "Total":
144 read_ios_s = float(parsed[u"All_ports_Read_IOs"])
145 write_ios_s = float(parsed[u"All_ports_Write_IOs"])
146 else:
147 read_ios_s = float(parsed[u"Read_IOs"][int(item) - 1])
148 write_ios_s = float(parsed[u"Write_IOs"][int(item) - 1])
149 total_ios_s = read_ios_s + write_ios_s
151 yield check_io_levels(read_ios_s, params.get("read"), "Read: %.2f 1/s", "disk_read_ios")
152 yield check_io_levels(write_ios_s, params.get("write"), "Write: %.2f 1/s", "disk_write_ios")
153 yield check_io_levels(total_ios_s, params.get("total"), "Total: %.2f 1/s")
156 check_info["ddn_s2a_stats.io"] = {
157 "default_levels_variable": "ddn_s2a_stats_io_default_levels",
158 "inventory_function": inventory_ddn_s2a_stats_io,
159 "check_function": check_ddn_s2a_stats_io,
160 "service_description": "DDN S2A IO %s",
161 "has_perfdata": True,
162 "group": "storage_iops",
166 # .--Data rate-----------------------------------------------------------.
167 # | ____ _ _ |
168 # | | _ \ __ _| |_ __ _ _ __ __ _| |_ ___ |
169 # | | | | |/ _` | __/ _` | | '__/ _` | __/ _ \ |
170 # | | |_| | (_| | || (_| | | | | (_| | || __/ |
171 # | |____/ \__,_|\__\__,_| |_| \__,_|\__\___| |
172 # | |
173 # '----------------------------------------------------------------------'
175 factory_settings["ddn_s2a_stats_default_levels"] = {
176 "total": (4800 * 1024 * 1024, 5500 * 1024 * 1024),
180 def inventory_ddn_s2a_stats(parsed):
181 if u"All_ports_Read_MBs" in parsed:
182 yield "Total", {}
183 for nr, _value in enumerate(parsed.get(u"Read_MBs", [])):
184 yield "%d" % (nr + 1), {}
187 def check_ddn_s2a_stats(item, params, parsed):
188 def check_datarate_levels(value, value_mb, levels, infotext_formatstring, perfname=None):
189 infotext = infotext_formatstring % value_mb
190 if levels is None:
191 perfdata = [(perfname, value)]
192 status = 0
193 else:
194 warn, crit = levels
195 warn_mb, crit_mb = [x / (1024 * 1024.0) for x in levels]
196 perfdata = [(perfname, value, warn, crit)]
197 levelstext = " (warn/crit at %.2f/%.2f MB/s)" % (warn_mb, crit_mb)
198 if value >= crit:
199 status = 2
200 infotext += levelstext
201 elif value >= warn:
202 status = 1
203 infotext += levelstext
204 else:
205 status = 0
207 if perfname is None:
208 return status, infotext
209 return status, infotext, perfdata
211 if item == "Total":
212 read_mb_s = float(parsed[u"All_ports_Read_MBs"])
213 write_mb_s = float(parsed[u"All_ports_Write_MBs"])
214 else:
215 read_mb_s = float(parsed[u"Read_MBs"][int(item) - 1])
216 write_mb_s = float(parsed[u"Write_MBs"][int(item) - 1])
217 total_mb_s = read_mb_s + write_mb_s
218 read = read_mb_s * 1024 * 1024
219 write = write_mb_s * 1024 * 1024
220 total = total_mb_s * 1024 * 1024
222 yield check_datarate_levels(read, read_mb_s, params.get("read"), "Read: %.2f MB/s",
223 "disk_read_throughput")
224 yield check_datarate_levels(write, write_mb_s, params.get("write"), "Write: %.2f MB/s",
225 "disk_write_throughput")
226 yield check_datarate_levels(total, total_mb_s, params.get("total"), "Total: %.2f MB/s")
229 check_info["ddn_s2a_stats"] = {
230 "default_levels_variable": "ddn_s2a_stats_default_levels",
231 "parse_function": parse_ddn_s2a_stats,
232 "inventory_function": inventory_ddn_s2a_stats,
233 "check_function": check_ddn_s2a_stats,
234 "service_description": "DDN S2A Data Rate %s",
235 "includes": ["ddn_s2a.include"],
236 "group": "storage_throughput",
237 "has_perfdata": True,