/usr/share/check_mk/checks/kernel is in check-mk-server 1.2.6p12-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | #!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# | ____ _ _ __ __ _ __ |
# | / ___| |__ ___ ___| | __ | \/ | |/ / |
# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
# | | |___| | | | __/ (__| < | | | | . \ |
# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
# | |
# | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation in version 2. check_mk is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
# .--kernel--Counters----------------------------------------------------.
# | ____ _ |
# | / ___|___ _ _ _ __ | |_ ___ _ __ ___ |
# | | | / _ \| | | | '_ \| __/ _ \ '__/ __| |
# | | |__| (_) | |_| | | | | || __/ | \__ \ |
# | \____\___/ \__,_|_| |_|\__\___|_| |___/ |
# | |
# +----------------------------------------------------------------------+
# | Check page faults, context switches and process creations |
# '----------------------------------------------------------------------'
# Inventory creates three checks per default:
inventory_kernel_counters = [ "pgmajfault", "ctxt", "processes" ]
kernel_default_levels = None
kernel_counter_names = {
"ctxt" : "Context Switches",
"processes" : "Process Creations",
"pgmajfault" : "Major Page Faults",
}
def inventory_kernel(info):
inventory = []
for counter in inventory_kernel_counters:
hits = [ line[0] for line in info[1:] if line[0] == counter ]
if len(hits) == 1:
countername = kernel_counter_names.get(counter, counter)
inventory.append( (countername, "kernel_default_levels") )
return inventory
# item is one of the keys in /proc/stat or /proc/vmstat
def check_kernel(item, params, info):
this_time = int(info[0][0])
hits = [ (line[0], line[1])
for line in info[1:]
if line[0] == item or kernel_counter_names.get(line[0], line[0]) == item ]
if len(hits) == 0:
return (3, "item '%s' not found in agent output" % item)
elif len(hits) > 1:
return (3, "item '%s' not unique (found %d times)" % (item, len(hits)))
counter = hits[0][0]
this_val = int(hits[0][1])
per_sec = get_rate("kernel." + counter, this_time, this_val)
if type(params) == tuple:
warn, crit = params
else:
warn, crit = None, None
perfdata = [ (counter, per_sec, warn, crit) ]
state, text, extraperf = check_levels(per_sec, counter, params)
perfdata += extraperf
infotext = "%.0f/s" % per_sec
if text:
infotext += ", " + text
return state, infotext, perfdata
check_info["kernel"] = {
'check_function': check_kernel,
'inventory_function': inventory_kernel,
'service_description': 'Kernel %s',
'has_perfdata': True,
'group': 'vm_counter',
}
#.
# .--kernel.util--CPU Utilization----------------------------------------.
# | _ _ _ _ _ _ _ _ |
# | | | | | |_(_) (_)______ _| |_(_) ___ _ __ |
# | | | | | __| | | |_ / _` | __| |/ _ \| '_ \ |
# | | |_| | |_| | | |/ / (_| | |_| | (_) | | | | |
# | \___/ \__|_|_|_/___\__,_|\__|_|\___/|_| |_| |
# | |
# +----------------------------------------------------------------------+
# | Check system/user/io-wait |
# '----------------------------------------------------------------------'
kernel_util_default_levels = None
def inventory_cpu_utilization(info):
for x in info:
if len(x) > 0 and x[0] == 'cpu':
return [(None, {})]
# Columns of cpu usage /proc/stat:
# - cpuX: number of CPU or only 'cpu' for aggregation
# - user: normal processes executing in user mode
# - nice: niced processes executing in user mode
# - system: processes executing in kernel mode
# - idle: twiddling thumbs
# - iowait: waiting for I/O to complete
# - irq: servicing interrupts
# - softirq: servicing softirqs
# - steal: involuntary wait
def kernel_check_cpu_utilization(item, params, info):
# Convert old style tuple-parameter to new dict
if type(params) != dict:
params = { "iowait": params }
# Look for entry beginning with "cpu"
f = [ l for l in info if l[0] == "cpu" ]
if len(f) != 1:
return 3, "More than one line with CPU info found. This check is not cluster-enabled."
line = f[0]
if len(line) < 8:
line = line + ['0', '0', '0', '0'] # needed for Linux 2.4
# line contains now the following columns:
# 'cpu' user nice system idle wait hw-int sw-int (steal ...)
# convert number to int
values = [ int(x) for x in line[1:8] ]
return check_cpu_util_unix(values, params)
check_info["kernel.util"] = {
'check_function': kernel_check_cpu_utilization,
'inventory_function': inventory_cpu_utilization,
'service_description': 'CPU utilization',
'has_perfdata': True,
'default_levels_variable': 'kernel_util_default_levels',
'group': 'cpu_iowait',
'includes': ['cpu_util.include'],
}
|