/usr/share/check_mk/checks/kernel is in check-mk-server 1.1.12-1ubuntu1.
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 2010 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.
# Inventory creates three checks per default:
inventory_kernel_counters = [ "pgmajfault", "ctxt", "processes" ]
kernel_default_levels = (None, 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, "UNKNOWN - item '%s' not found in agent output" % item)
elif len(hits) > 1:
return (3, "UNKNOWN - item '%s' not unique (found %d times)" % (item, len(hits)))
counter = hits[0][0]
this_val = int(hits[0][1])
timedif, per_sec = get_counter("kernel." + item, this_time, this_val)
infotext = " - %.0f/s in last %d secs" % (per_sec, timedif)
if params == None:
return (0, "OK" + infotext, [ (counter, per_sec) ])
warn, crit = params
perfdata = [ (counter, per_sec, warn, crit) ]
if warn == None and crit != None:
infotext += " (critical at %.0f/s)" % crit
elif warn != None and crit == None:
infotext += " (warning at %.0f/s)" % warn
elif warn != None:
infotext += " (warn/crit at %.0f/%.0f per sec)" % (warn, crit)
if crit != None and per_sec >= crit:
return (2, "CRIT" + infotext, perfdata)
elif warn != None and per_sec >= warn:
return (1, "WARN" + infotext, perfdata)
else:
return (0, "OK" + infotext, perfdata)
kernel_util_default_levels = None
def inventory_cpu_utilization(info):
for x in info:
if len(x) > 0 and x[0] == 'cpu':
return [(None, "kernel_util_default_levels")]
# 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 check_cpu_utilization(item, params, info):
global g_counters
# Look for entry beginning with "cpu"
f = [ l for l in info if l[0] == "cpu" ]
if len(f) != 1:
return (3, "UNKNOWN - invalid output from plugin")
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] ]
this_time = int(time.time())
diff_values = []
n = 0
for v in values:
n += 1
countername = "cpu.util.%d" % n
last_time, last_val = g_counters.get(countername, (0, 0))
diff_values.append(v - last_val)
g_counters[countername] = (this_time, v)
sum_jiffies = sum(diff_values[0:7]) # do not account for steal!
if sum_jiffies == 0:
return (0, "OK - too short interval")
user = diff_values[0] + diff_values[1] # add user + nice
system = diff_values[2]
wait = diff_values[4]
user_perc = 100.0 * float(user) / float(sum_jiffies)
system_perc = 100.0 * float(system) / float(sum_jiffies)
wait_perc = 100.0 * float(wait) / float(sum_jiffies)
perfdata = [
( "user", "%.3f" % user_perc ),
( "system", "%.3f" % system_perc ),
( "wait", "%.3f" % wait_perc ) ]
# You may set a warning/critical level on the io wait
# percentage. This can be done by setting params to
# a pair of (warn, crit)
result = (0, "OK")
try:
warn, crit = params
if wait_perc >= crit:
result = (2, "CRIT (wait too large)")
elif wait_perc >= warn:
result = (1, "WARNING (wait too large)")
except:
pass
return (result[0], result[1] + " - user: %2.1f%%, system: %2.1f%%, wait: %2.1f%%" %
(user_perc, system_perc, wait_perc), perfdata)
check_info['kernel.util'] = (check_cpu_utilization, "CPU utilization", 1, inventory_cpu_utilization)
check_info['kernel'] = (check_kernel, "Kernel %s", 1, inventory_kernel)
|