2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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.
28 def parse_hr_mem(info
):
30 '.1.3.6.1.2.1.25.2.1.1': 'other',
31 '.1.3.6.1.2.1.25.2.1.2': 'RAM',
32 '.1.3.6.1.2.1.25.2.1.3': 'virtual memory',
33 '.1.3.6.1.2.1.25.2.1.4': 'fixed disk',
34 '.1.3.6.1.2.1.25.2.1.5': 'removeable disk',
35 '.1.3.6.1.2.1.25.2.1.6': 'floppy disk',
36 '.1.3.6.1.2.1.25.2.1.7': 'compact disk',
37 '.1.3.6.1.2.1.25.2.1.8': 'RAM disk',
38 '.1.3.6.1.2.1.25.2.1.9': 'flash memory',
39 '.1.3.6.1.2.1.25.2.1.10': 'network disk',
43 for hrtype
, hrdescr
, hrunits
, hrsize
, hrused
in info
:
45 size
= int(hrsize
) * int(hrunits
) / 1048576.0
46 used
= int(hrused
) * int(hrunits
) / 1048576.0
47 parsed
.setdefault(map_types
[hrtype
], []).append((hrdescr
.lower(), size
, used
))
48 except (ValueError, KeyError):
54 memused_default_levels
= (150.0, 200.0)
57 # Memory information is - together with filesystems - in
58 # hrStorage. We need the entries of the types hrStorageVirtualMemory
60 def inventory_hr_mem(parsed
):
61 # Do we find at least one entry concerning memory?
62 for _
, size
, __
in parsed
.get('RAM', []) + parsed
.get('virtual memory', []):
64 # some device have zero (broken) values
65 return [(None, "memused_default_levels")]
68 def check_hr_mem(_no_item
, params
, parsed
):
69 # This check does not yet support averaging. We need to
70 # convert it to mem.include
71 if isinstance(params
, dict):
72 params
= params
["levels"]
76 for type_readable
, entries
in parsed
.iteritems():
77 for descr
, size
, used
in entries
:
78 if type_readable
in ['RAM', 'virtual memory'] and descr
!= "virtual memory":
79 # We use only the first entry of each type. We have
80 # seen devices (pfSense), that have lots of additional
81 # entries that are not useful.
82 usage
.setdefault(type_readable
, (size
, used
))
84 if descr
in ["cached memory", "memory buffers"] and used
> 0:
85 # Account for cached memory (this works at least for systems using
86 # the UCD snmpd (such as Linux based applicances)
87 # some devices report negative used cache values...
90 totalram_mb
, ramused_mb
= usage
.get("RAM", (0, 0))
91 ramused_mb
-= cached_mb
92 totalvirt_mb
, virtused_mb
= usage
.get("virtual memory", (0, 0))
93 totalmem_mb
, totalused_mb
= totalram_mb
+ totalvirt_mb
, ramused_mb
+ virtused_mb
95 if totalmem_mb
> 0 and totalram_mb
> 0:
96 totalused_perc
= 100 * totalused_mb
/ totalram_mb
98 perfdata
= [('ramused', str(ramused_mb
) + 'MB', None, None, 0, totalram_mb
),
99 ('swapused', str(virtused_mb
) + 'MB', None, None, 0, totalvirt_mb
)]
101 infotext
= "%.2f GB used (%.2f GB RAM + %.2f GB SWAP, this is %.1f%% of %.2f GB RAM)" % \
102 (totalused_mb
/ 1024.0, ramused_mb
/ 1024, virtused_mb
/ 1024, totalused_perc
, totalram_mb
/ 1024.0)
105 if isinstance(warn
, float):
106 perfdata
.append(('memused', str(totalused_mb
) + 'MB', int(warn
/ 100.0 * totalram_mb
),
107 int(crit
/ 100.0 * totalram_mb
), 0, totalvirt_mb
))
108 if totalused_perc
>= crit
:
109 return (2, '%s, critical at %.1f%%' % (infotext
, crit
), perfdata
)
110 elif totalused_perc
>= warn
:
111 return (1, '%s, warning at %.1f%%' % (infotext
, warn
), perfdata
)
112 return (0, '%s' % infotext
, perfdata
)
114 perfdata
.append(('memused', str(totalused_mb
) + 'MB', warn
, crit
, 0, totalram_mb
))
115 if totalused_mb
>= crit
:
116 return (2, '%s, critical at %.2f GB' % (infotext
, crit
/ 1024.0), perfdata
)
117 elif totalused_mb
>= warn
:
118 return (1, '%s, warning at %.2f GB' % (infotext
, warn
/ 1024.0), perfdata
)
119 return (0, '%s' % infotext
, perfdata
)
121 return 3, "Invalid information. Total memory is empty."
124 check_info
["hr_mem"] = {
125 'parse_function': parse_hr_mem
,
126 'inventory_function': inventory_hr_mem
,
127 'check_function': check_hr_mem
,
128 'service_description': 'Memory used',
129 'has_perfdata': True,
131 '.1.3.6.1.2.1.25.2.3.1',
135 4, # hrStorageAllocationUnits
139 # Some devices are reporting wrong data on
140 # HOST-RESOURCES-MIB. Use UCD-MIB in these
142 'snmp_scan_function': is_hr_mem
,
144 'includes': ["ucd_hr.include"]