2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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:
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
)
44 yield 0, 'Limit: n.a.'
46 yield 0, 'Limit: %s' % readable(limit
), [('k8s_%s_limit' % name
, limit
)]
48 allocatable
= parsed
.get('allocatable', {}).get(name
, default
)
50 yield 0, 'Allocatable: %s' % readable(allocatable
), [('k8s_%s_allocatable' % name
,
53 capacity
= parsed
.get('capacity', {}).get(name
, default
)
55 yield 0, 'Capacity: %s' % readable(capacity
), [('k8s_%s_capacity' % name
, capacity
)]
58 usage
= 100.0 * request
/ allocatable
61 'k8s_%s_usage' % name
,
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',
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',
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',
95 'group': 'k8s_resources',