/usr/share/check_mk/checks/mem.include 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 | #!/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.
memused_default_levels = (150.0, 200.0)
factory_settings["memory_default_levels"] = {
"levels" : memused_default_levels,
}
def check_memory(params, meminfo):
swapused = meminfo['SwapTotal'] - meminfo['SwapFree']
memused = meminfo['MemTotal'] - meminfo['MemFree']
# Buffers and Cached are optional. On Linux both mean basically the same.
caches = meminfo.get('Buffers', 0) + meminfo.get('Cached', 0)
# Size of Pagetable on Linux can be relevant e.g. on ORACLE
# servers with much memory, that do not use HugeTables. We account
# that for used
pagetables = meminfo.get('PageTables', 0)
pagetables_mb = pagetables / 1024.0
totalused_kb = (swapused + memused - caches + pagetables)
totalused_mb = totalused_kb / 1024.0
totalmem_kb = meminfo['MemTotal']
totalmem_mb = totalmem_kb / 1024.0
totalused_perc = 100 * (float(totalused_kb) / float(totalmem_kb))
totalvirt_mb = (meminfo['SwapTotal'] + meminfo['MemTotal']) / 1024.0
if type(params) == tuple:
params = { "levels" : params }
warn, crit = params["levels"]
if pagetables > 0:
pgtext = " + %.2f Pagetables" % (pagetables_mb / 1024.0)
else:
pgtext = ""
infotext = "%.2f GB used (%.2f RAM + %.2f SWAP%s, this is %.1f%% of %.2f RAM (%.2f total SWAP)" % \
(totalused_mb / 1024.0, (memused-caches) / 1024.0 / 1024, swapused / 1024.0 / 1024,
pgtext, totalused_perc, totalmem_mb / 1024.0, meminfo["SwapTotal"] / 1024.0 / 1024)
# Take into account averaging
average_min = params.get("average")
if average_min:
totalused_mb_avg = get_average("mem.used.total", time.time(),
totalused_mb, average_min, initialize_zero = False)
totalused_perc_avg = totalused_mb_avg / totalmem_mb * 100
infotext += ", %d min average %.1f%%" % (average_min, totalused_perc_avg)
comp_mb = totalused_mb_avg
else:
comp_mb = totalused_mb
infotext += ")"
# levels may be given either in int -> MB or in float -> percentages. So convert
# effective levels to MB now
if type(warn) == float:
warn_mb = int(warn/100.0 * totalmem_mb)
crit_mb = int(crit/100.0 * totalmem_mb)
leveltext = lambda x: "%.1f%%" % x
else:
warn_mb = warn
crit_mb = crit
leveltext = lambda x: "%.2f GB" % (x / 1024.0)
# Prepare performance data
perfdata = [
('ramused', str( (memused - caches) / 1024) + 'MB', '', '', 0, totalmem_mb),
('swapused', str(swapused / 1024) + 'MB', '', '', 0, meminfo['SwapTotal']/1024),
('memused', str(totalused_mb) + 'MB', warn_mb, crit_mb, 0, totalvirt_mb),
]
if average_min:
perfdata.append(('memusedavg', str(totalused_mb_avg)+'MB'))
# Check levels
state = 0
if warn_mb > 0: # positive levels - used memory
if comp_mb >= crit_mb:
state = 2
infotext += ", critical at %s used" % leveltext(crit)
elif comp_mb >= warn_mb:
state = 1
infotext += ", warning at %s used" % leveltext(warn)
else: # negative levels - free memory
freemem_mb = totalvirt_mb - comp_mb
if freemem_mb <= -crit_mb:
state = 2
infotext += ", critical at %s free" % leveltext(-crit)
elif freemem_mb <= -warn_mb:
state = 1
infotext += ", warning at %s free" % leveltext(-warn)
# Add additional metrics, provided by Linux.
mapped = meminfo.get('Mapped')
if mapped:
mapped_mb = int(mapped) / 1024
committed_as_mb = int(meminfo.get('Committed_AS', 0)) / 1024
shared_mb = int(meminfo.get('Shmem', 0)) / 1024
perfdata += [
('mapped', str(mapped_mb) + 'MB'),
('committed_as', str(committed_as_mb) + 'MB'),
('pagetables', str(pagetables_mb) + 'MB'),
('shared', str(shared_mb) + 'MB'),
]
infotext += ", %.1f mapped, %.1f committed, %.1f shared" % \
(mapped_mb / 1024.0, committed_as_mb / 1024.0, shared_mb / 1024.0)
return state, infotext, perfdata
|