Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / filehandler
blob2e649797389e66720e8f005926a0ff21aa217fc2
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 # Measures total allocated file handles.
28 # The output displays
29 # - the number of allocated file handles
30 # - the number of allocatedly used file handles (with the 2.4 kernel); or
31 # the number of allocatedly unused file handles (with the 2.6 kernel)
32 # - the maximum files handles that can be allocated
33 # (can also be found in /proc/sys/fs/file-max)
34 # Example output of '/proc/sys/fs/file-nr':
35 # <<<filehandler>>>
36 # 9376 0 817805
38 factory_settings['filehandler_default_levels'] = {'levels': (80.0, 90.0)}
41 def inventory_filehandler(info):
42 return [(None, {})]
45 def check_filehandler(_no_item, params, info):
46 allocated, _used_or_unused, maximum = info[0]
47 state = 0
48 perc = float(allocated) / float(maximum) * 100.0
49 infotext = '%.1f%% used (%s of %s file handles)' % (perc, allocated, maximum)
50 warn, crit = params['levels']
52 if perc >= crit:
53 state = 2
54 elif perc >= warn:
55 state = 1
56 if state > 0:
57 infotext += ' (warn/crit at %.1f%%/%.1f%%)' % (warn, crit)
59 return state, infotext, [('filehandler_perc', perc, warn, crit)]
62 check_info['filehandler'] = {
63 'check_function': check_filehandler,
64 'inventory_function': inventory_filehandler,
65 'service_description': 'Filehandler',
66 'has_perfdata': True,
67 'default_levels_variable': 'filehandler_default_levels',
68 'group': 'filehandler',