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.
27 from cmk
.special_agents
.agent_kubernetes
import parse_frac_prefix
30 def parse_mul_prefix(value
):
32 if value
.endswith('k'):
33 return 1000 * int(value
[:-1])
38 def check_k8s_pods_memory(item
, _no_params
, metrics
):
45 for pod_data
in metrics
:
46 rss
+= parse_mul_prefix(pod_data
['metrics']['memory_rss'])
47 swap
+= parse_mul_prefix(pod_data
['metrics']['memory_swap'])
48 usage_bytes
+= parse_mul_prefix(pod_data
['metrics']['memory_usage_bytes'])
49 max_usage_bytes
+= parse_mul_prefix(pod_data
['metrics']['memory_max_usage_bytes'])
51 yield check_levels(rss
, 'rss', _no_params
, human_readable_func
=get_bytes_human_readable
)
52 yield check_levels(swap
, 'swap', _no_params
, human_readable_func
=get_bytes_human_readable
)
54 usage_bytes
, 'usage_bytes', _no_params
, human_readable_func
=get_bytes_human_readable
)
59 human_readable_func
=get_bytes_human_readable
)
62 check_info
['k8s_pods_memory'] = {
63 'parse_function': parse_k8s
,
64 'inventory_function': discover(),
65 'check_function': check_k8s_pods_memory
,
66 'service_description': 'Memory usage for Pods in %s namespace',
67 'includes': ['k8s.include'],
72 def check_k8s_pods_cpu(item
, _no_params
, metrics
):
78 for pod_data
in metrics
:
79 system
+= parse_frac_prefix(pod_data
['metrics']['cpu_system'])
80 user
+= parse_frac_prefix(pod_data
['metrics']['cpu_user'])
81 usage
+= parse_frac_prefix(pod_data
['metrics']['cpu_usage'])
83 yield check_levels(system
, 'system', _no_params
)
84 yield check_levels(user
, 'user', _no_params
)
85 yield check_levels(usage
, 'usage', _no_params
)
88 check_info
['k8s_pods_cpu'] = {
89 'parse_function': parse_k8s
,
90 'inventory_function': discover(),
91 'check_function': check_k8s_pods_cpu
,
92 'service_description': 'CPU usage for Pods in %s namespace',
93 'includes': ['k8s.include'],
98 def check_k8s_pods_fs(item
, _no_params
, metrics
):
106 for pod_data
in metrics
:
107 inodes
+= parse_frac_prefix(pod_data
['metrics']['fs_inodes'])
108 reads
+= parse_frac_prefix(pod_data
['metrics']['fs_reads'])
109 writes
+= parse_frac_prefix(pod_data
['metrics']['fs_writes'])
110 limit_bytes
+= parse_mul_prefix(pod_data
['metrics']['fs_limit_bytes'])
111 usage_bytes
+= parse_mul_prefix(pod_data
['metrics']['fs_usage_bytes'])
113 yield check_levels(inodes
, 'inodes', _no_params
)
114 yield check_levels(reads
, 'reads', _no_params
)
115 yield check_levels(writes
, 'writes', _no_params
)
117 limit_bytes
, 'limit_bytes', _no_params
, human_readable_func
=get_bytes_human_readable
)
119 usage_bytes
, 'usage_bytes', _no_params
, human_readable_func
=get_bytes_human_readable
)
122 check_info
['k8s_pods_fs'] = {
123 'parse_function': parse_k8s
,
124 'inventory_function': discover(),
125 'check_function': check_k8s_pods_fs
,
126 'service_description': 'FS usage for Pods in %s namespace',
127 'includes': ['k8s.include'],