Cleanup config.nodes_of
[check_mk.git] / checks / k8s_resources
blob45b61613c1eefb9f226f55ea1b191b8c714a1bb8
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2018 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 get_k8s_resources_inventory_function(name):
29 def inventory_function(parsed):
30 if parsed.get('requests', {}).get(name) is not None:
31 return [(None, {})]
33 return inventory_function
36 def get_k8s_resources_check_function(name, default, readable):
37 def check_resources(_no_item, params, parsed):
38 request = parsed.get('requests', {}).get(name, default)
39 yield 0, 'Request: %s' % readable(request), [('k8s_%s_request' % name, request)]
41 limit = parsed.get('limits', {}).get(name)
42 if limit:
43 if math.isinf(limit):
44 yield 0, 'Limit: n.a.'
45 elif limit:
46 yield 0, 'Limit: %s' % readable(limit), [('k8s_%s_limit' % name, limit)]
48 allocatable = parsed.get('allocatable', {}).get(name, default)
49 if allocatable:
50 yield 0, 'Allocatable: %s' % readable(allocatable), [('k8s_%s_allocatable' % name,
51 allocatable)]
53 capacity = parsed.get('capacity', {}).get(name, default)
54 if capacity:
55 yield 0, 'Capacity: %s' % readable(capacity), [('k8s_%s_capacity' % name, capacity)]
57 if allocatable:
58 usage = 100.0 * request / allocatable
59 yield check_levels(
60 usage,
61 'k8s_%s_usage' % name,
62 params.get(name),
63 infoname='Usage',
64 human_readable_func=get_percent_human_readable)
66 return check_resources
69 check_info['k8s_resources'] = {
70 'parse_function': parse_k8s,
71 'includes': ['k8s.include'],
74 check_info['k8s_resources.pods'] = {
75 'inventory_function': get_k8s_resources_inventory_function('pods'),
76 'check_function': get_k8s_resources_check_function('pods', 0, str),
77 'service_description': 'Pod resources',
78 'has_perfdata': True,
79 'group': 'k8s_resources',
82 check_info['k8s_resources.cpu'] = {
83 'inventory_function': get_k8s_resources_inventory_function('cpu'),
84 'check_function': get_k8s_resources_check_function('cpu', 0.0, lambda x: '%.3f' % x),
85 'service_description': 'CPU resources',
86 'has_perfdata': True,
87 'group': 'k8s_resources',
90 check_info['k8s_resources.memory'] = {
91 'inventory_function': get_k8s_resources_inventory_function('memory'),
92 'check_function': get_k8s_resources_check_function('memory', 0.0, get_bytes_human_readable),
93 'service_description': 'Memory resources',
94 'has_perfdata': True,
95 'group': 'k8s_resources',