Cleanup config.nodes_of
[check_mk.git] / checks / winperf
blob8a72b636235f270fb12c688b05920ca29241861f
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2014 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 inventory_win_cpuusage(info):
29 for line in info:
30 try:
31 if line[0] == '238:6':
32 return [(None, {})]
33 except:
34 pass
37 def check_win_cpuusage(item, params, info):
38 if isinstance(params, tuple):
39 warn, crit = params
40 elif isinstance(params, dict):
41 warn, crit = params['levels']
42 else: # legacy: old params may be None
43 warn, crit = None, None
45 for line in info:
46 if line[0] == '238:6':
47 this_time = int(float(line[1]))
48 # Windows sends one counter for each CPU plus one counter that
49 # I've forgotton what's it for (idle?)
50 num_cpus = len(line) - 4
51 overall_perc = 0
52 for cpu in range(0, num_cpus):
53 ticks = int(line[2 + cpu])
54 ticks_per_sec = get_rate("cpuusage.%d" % cpu, this_time, ticks)
55 secs_per_sec = ticks_per_sec / 10000000.0
56 used_perc = 100 * (1 - secs_per_sec)
57 overall_perc += used_perc
59 used_perc = overall_perc / num_cpus
60 if used_perc < 0:
61 used_perc = 0
62 elif used_perc > 100:
63 used_perc = 100
65 if num_cpus == 1:
66 num_txt = ""
67 else:
68 num_txt = " / %d CPUs" % num_cpus
70 infotext = "%d%% used%s" % (int(used_perc), num_txt)
71 state = 0
72 if crit is not None and used_perc >= crit:
73 state = 2
74 elif warn is not None and used_perc >= warn:
75 state = 1
76 if state:
77 infotext += " (warn/crit at %s/%s)" % (get_percent_human_readable(warn),
78 get_percent_human_readable(crit))
79 return state, infotext, [("cpuusage", "%.2f" % used_perc, warn, crit, 0, 100)]
80 return (3, "counter for cpu (238:6) not found")
83 def inventory_win_diskstat(info):
84 for line in info:
85 try:
86 if line[0] == '2:16' or line[0] == '2:18':
87 return [(None, None, None)]
88 except:
89 pass
90 return []
93 def check_win_diskstat(item, params, info):
94 read_bytes_ctr = 0
95 write_bytes_ctr = 0
96 this_time = None
97 for line in info:
98 if line[0] == '2:16':
99 read_bytes_ctr = int(line[2])
100 elif line[0] == '2:18':
101 write_bytes_ctr = int(line[2])
102 this_time = int(float(line[1]))
103 break
105 if not this_time:
106 return
108 try:
109 read_per_sec = get_rate("diskstat.read", this_time, read_bytes_ctr)
110 write_per_sec = get_rate("diskstat.write", this_time, write_bytes_ctr)
111 except MKCounterWrapped, e:
112 # make sure that inital check does not need three cycles for all counters
113 # to be initialized
114 get_rate("diskstat.write", this_time, write_bytes_ctr)
115 raise e
117 perfdata = [("read", "%dc" % read_bytes_ctr), ("write", "%dc" % write_bytes_ctr)]
118 return (
120 "reading %.1f MB/s, writing %.1f MB/s" % (read_per_sec / 1048576, write_per_sec / 1048576),
121 perfdata)
124 check_info["winperf.cpuusage"] = {
125 'check_function': check_win_cpuusage,
126 'inventory_function': inventory_win_cpuusage,
127 'service_description': 'CPU Usage',
128 'has_perfdata': True,
129 'default_levels_variable': 'winperf_cpu_default_levels',
130 'includes': ["winperf.include"],
133 check_info["winperf.diskstat"] = {
134 'check_function': check_win_diskstat,
135 'inventory_function': inventory_win_diskstat,
136 'service_description': 'Disk IO',
137 'has_perfdata': True,