Cleanup config.nodes_of
[check_mk.git] / checks / cpu
blob59313e0f80e6298bc3b66308315a33b16a836ec4
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.
27 # Output is taken from /proc/loadavg plus the number of cores:
28 # 0.26 0.47 0.52 2/459 19531 4
30 # .--Load----------------------------------------------------------------.
31 # | _ _ |
32 # | | | ___ __ _ __| | |
33 # | | | / _ \ / _` |/ _` | |
34 # | | |__| (_) | (_| | (_| | |
35 # | |_____\___/ \__,_|\__,_| |
36 # | |
37 # '----------------------------------------------------------------------'
39 cpuload_default_levels = (5.0, 10.0)
42 def inventory_cpu_load(info):
43 if len(info) >= 1 and len(info[0]) >= 5:
44 return [(None, "cpuload_default_levels")]
47 def check_cpu_load(item, params, info):
48 if not info:
49 return None
51 if len(info[0]) >= 6:
52 # There have been broken AIX agents for a long time which produced data like follows.
53 # Newer agents deal with this, but to be nice to old agents: deal with it.
54 # <<<cpu>>>
55 # 0.00 0.00 0.00 1/97 8913088 aixxyz configuration: @lcpu=8 @mem=24576MB @ent=0.20
56 line = " ".join(info[0])
57 if "lcpu=" in line:
58 for part in info[0]:
59 if "lcpu=" in part:
60 num_cpus = int(part.split("=", 1)[1])
61 break
62 else:
63 num_cpus = int(info[0][5])
64 else:
65 num_cpus = 1
67 load = map(float, info[0][0:3])
68 return check_cpu_load_generic(params, load, num_cpus)
71 check_info["cpu.loads"] = {
72 "check_function": check_cpu_load,
73 "inventory_function": inventory_cpu_load,
74 "service_description": "CPU load",
75 "has_perfdata": True,
76 "group": "cpu_load",
77 "includes": ["cpu_load.include"],
78 "handle_real_time_checks": True,
82 # .--Threads-------------------------------------------------------------.
83 # | _____ _ _ |
84 # | |_ _| |__ _ __ ___ __ _ __| |___ |
85 # | | | | '_ \| '__/ _ \/ _` |/ _` / __| |
86 # | | | | | | | | | __/ (_| | (_| \__ \ |
87 # | |_| |_| |_|_| \___|\__,_|\__,_|___/ |
88 # | |
89 # '----------------------------------------------------------------------'
91 threads_default_levels = {} # legacy default levels variable
93 factory_settings["cpu_threads_default_levels"] = {
94 "levels": (2000, 4000),
98 def inventory_cpu_threads(info):
99 if len(info) >= 1 and len(info[0]) >= 5:
100 return [(None, {})]
103 def check_cpu_threads(item, params, info):
104 if isinstance(params, tuple):
105 params = {'levels': params}
107 try:
108 num_threads = int(info[0][3].split('/')[1])
109 except:
110 yield (3, "invalid output from plugin")
111 return
113 absolute_levels = params.get("levels", (None, None))
114 yield check_levels(
115 num_threads,
116 'threads',
117 absolute_levels,
118 unit="threads",
119 human_readable_func=lambda x: "%.f" % x,
120 infoname="Count")
122 if len(info) > 1:
123 max_threads = int(info[1][0])
124 thread_usage = 100.0 * num_threads / max_threads
125 relative_levels = params.get("levels_percent", (None, None))
126 yield check_levels(
127 thread_usage,
128 'thread_usage',
129 relative_levels,
130 human_readable_func=get_percent_human_readable,
131 infoname="Usage")
134 check_info["cpu.threads"] = {
135 "check_function": check_cpu_threads,
136 "inventory_function": inventory_cpu_threads,
137 "service_description": "Number of threads",
138 "has_perfdata": True,
139 "group": "threads",
140 "default_levels_variable": "cpu_threads_default_levels",
141 "handle_real_time_checks": True,