2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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
):
31 if line
[0] == '238:6':
37 def check_win_cpuusage(item
, params
, info
):
38 if isinstance(params
, tuple):
40 elif isinstance(params
, dict):
41 warn
, crit
= params
['levels']
42 else: # legacy: old params may be None
43 warn
, crit
= None, None
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
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
68 num_txt
= " / %d CPUs" % num_cpus
70 infotext
= "%d%% used%s" % (int(used_perc
), num_txt
)
72 if crit
is not None and used_perc
>= crit
:
74 elif warn
is not None and used_perc
>= warn
:
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
):
86 if line
[0] == '2:16' or line
[0] == '2:18':
87 return [(None, None, None)]
93 def check_win_diskstat(item
, params
, info
):
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]))
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
114 get_rate("diskstat.write", this_time
, write_bytes_ctr
)
117 perfdata
= [("read", "%dc" % read_bytes_ctr
), ("write", "%dc" % write_bytes_ctr
)]
120 "reading %.1f MB/s, writing %.1f MB/s" % (read_per_sec
/ 1048576, write_per_sec
/ 1048576),
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,