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_winperf_util(info
):
40 def check_winperf_util(_no_item
, params
, info
):
44 this_time
= int(float(info
[0][0]))
46 what_map
= {"-232": "util", "-96": "user", "-94": "privileged"}
50 if line
[0] in what_map
:
51 winperf_lines
.append(line
)
58 for line
in winperf_lines
:
59 if line
[0] in what_map
:
61 what
= what_map
[line
[0]]
62 # Windows sends one counter for each CPU plus one counter that
63 # sums up to total (called _Total). We only need that last value.
65 num_cpus
= len(line
) - 3
68 get_rate("winperf_util.%s" % what
, this_time
, ticks
, onwrap
= RAISE
)
69 except MKCounterWrapped
:
72 # We get the value of the PERF_100NSEC_TIMER_INV here.
73 # This counter type shows the average percentage of active time observed
74 # during the sample interval. This is an inverse counter. Counters of this
75 # type calculate active time by measuring the time that the service was
76 # inactive and then subtracting the percentage of active time from 100 percent.
78 # 1 tick = 100ns, convert to seconds
79 cpusecs_per_sec
= ticks_per_sec
/ 10000000.0
82 used_perc
= 100.0 * (1 - cpusecs_per_sec
)
84 used_perc
= 100.0 * cpusecs_per_sec
86 # Due to timeing invariancies the measured level can become > 100%.
87 # This makes users unhappy, so cut it off.
95 for i
in range(num_cpus
):
96 core_ticks
= int(line
[1 + i
])
98 core_ticks_per_sec
= get_rate(
99 "winperf_util.core%d.util" % i
, this_time
, core_ticks
, onwrap
=RAISE
)
100 except MKCounterWrapped
:
102 core_ticks_per_sec
= 0
103 core_cpusecs_per_sec
= core_ticks_per_sec
/ 10000000.0
104 core_used_perc
= 100.0 * (1 - core_cpusecs_per_sec
)
105 # clamp percentage to the range 0-100
106 core_used_perc
= min(100.0, max(0.0, core_used_perc
))
107 cores
.append(("core%d" % i
, core_used_perc
))
110 for status
, infotext
, perfdata
in check_cpu_util(used_perc
, params
, this_time
,
112 if perfdata
and perfdata
[0][0] == "util":
113 perfdata
[0] = perfdata
[0][:5] + (num_cpus
,)
114 yield status
, infotext
, perfdata
116 yield 0, "%s perc: %.1f %%" % (what
, used_perc
), [(what
, used_perc
)]
118 yield 0, "%s perc: %.1f %%" % (what
, used_perc
)
124 # all counters initialized, NOW we can raise the exception
125 raise MKCounterWrapped("Counter wrap, skipping checks this time")
127 yield 0, "%d CPUs" % num_cpus
130 check_info
["winperf_processor.util"] = {
131 'check_function': check_winperf_util
,
132 'inventory_function': inventory_winperf_util
,
133 'service_description': 'CPU utilization',
134 'has_perfdata': True,
135 'handle_real_time_checks': True,
136 'group': 'cpu_utilization_os',
137 'default_levels_variable': 'winperf_cpu_default_levels',
138 'includes': ["cpu_util.include", "winperf.include"],