Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / kernel
blobe1104e5a27a0ec28234f1e46bd6378fe2de41c60
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 # .--kernel--Counters----------------------------------------------------.
28 # | ____ _ |
29 # | / ___|___ _ _ _ __ | |_ ___ _ __ ___ |
30 # | | | / _ \| | | | '_ \| __/ _ \ '__/ __| |
31 # | | |__| (_) | |_| | | | | || __/ | \__ \ |
32 # | \____\___/ \__,_|_| |_|\__\___|_| |___/ |
33 # | |
34 # +----------------------------------------------------------------------+
35 # | Check page faults, context switches and process creations |
36 # '----------------------------------------------------------------------'
38 # Inventory creates three checks per default:
39 inventory_kernel_counters = ["pgmajfault", "ctxt", "processes"]
40 kernel_default_levels = None
42 kernel_counter_names = {
43 "ctxt": "Context Switches",
44 "processes": "Process Creations",
45 "pgmajfault": "Major Page Faults",
49 def inventory_kernel(info):
50 inventory = []
51 for counter in inventory_kernel_counters:
52 hits = [line[0] for line in info[1:] if line[0] == counter]
53 if len(hits) == 1:
54 countername = kernel_counter_names.get(counter, counter)
55 inventory.append((countername, "kernel_default_levels"))
56 return inventory
59 # item is one of the keys in /proc/stat or /proc/vmstat
60 def check_kernel(item, params, info):
61 if not info:
62 return
64 this_time = int(info[0][0])
65 hits = [(line[0], line[1])
66 for line in info[1:]
67 if line[0] == item or kernel_counter_names.get(line[0], line[0]) == item]
68 if len(hits) == 0:
69 return (3, "item '%s' not found in agent output" % item)
70 elif len(hits) > 1:
71 return (3, "item '%s' not unique (found %d times)" % (item, len(hits)))
73 counter = hits[0][0]
74 this_val = int(hits[0][1])
75 per_sec = get_rate(None, this_time, this_val)
77 return check_levels(per_sec, counter, params, unit="/s", infoname=kernel_counter_names[counter])
80 check_info["kernel"] = {
81 'check_function': check_kernel,
82 'inventory_function': inventory_kernel,
83 'service_description': 'Kernel %s',
84 'has_perfdata': True,
85 'group': 'vm_counter',
88 # .--kernel.util--CPU Utilization----------------------------------------.
89 # | _ _ _ _ _ _ _ _ |
90 # | | | | | |_(_) (_)______ _| |_(_) ___ _ __ |
91 # | | | | | __| | | |_ / _` | __| |/ _ \| '_ \ |
92 # | | |_| | |_| | | |/ / (_| | |_| | (_) | | | | |
93 # | \___/ \__|_|_|_/___\__,_|\__|_|\___/|_| |_| |
94 # | |
95 # +----------------------------------------------------------------------+
96 # | Check system/user/io-wait |
97 # '----------------------------------------------------------------------'
100 def inventory_cpu_utilization(info):
101 for x in info:
102 if len(x) > 0 and x[0] == 'cpu':
103 return [(None, {})]
106 # Columns of cpu usage /proc/stat:
107 # - cpuX: number of CPU or only 'cpu' for aggregation
108 # - user: normal processes executing in user mode
109 # - nice: niced processes executing in user mode
110 # - system: processes executing in kernel mode
111 # - idle: twiddling thumbs
112 # - iowait: waiting for I/O to complete
113 # - irq: servicing interrupts
114 # - softirq: servicing softirqs
115 # - steal: Stolen time, which is the time spent in other operating systems
116 # when running in a virtualized environment (since Linux 2.6.11)
117 # - guest: Time spent running a virtual CPU for guest operating systems (since Linux 2.6.24)
118 # - guest_nice: Time spent running a niced guest (since Linux 2.6.33)
121 def kernel_check_cpu_utilization(item, params, info):
122 params = transform_cpu_iowait(params)
124 # Look for entry matching "cpu" (this is the combined load of all cores)
125 total = [cpu_info(line) for line in info if line[0] == "cpu"]
127 if len(total) != 1:
128 return 3, "More than one line with CPU info found. This check is not cluster-enabled."
130 cores = [cpu_info(line) for line in info if line[0].startswith("cpu") and len(line[0]) > 3]
131 # total contains now the following columns:
132 # 'cpu' user nice system idle wait hw-int sw-int (steal ...)
133 # convert number to int
134 return check_cpu_util_unix(total[0], params, cores)
137 check_info["kernel.util"] = {
138 'check_function': kernel_check_cpu_utilization,
139 'inventory_function': inventory_cpu_utilization,
140 'service_description': 'CPU utilization',
141 'has_perfdata': True,
142 'group': 'cpu_iowait',
143 'includes': ['cpu_util.include', 'transforms.include'],