Refactoring: Moved check parameters from unsorted.py to dedicated modules (CMK-1393)
[check_mk.git] / checks / k8s_pods_cm
blob037969e172339641bf8d2730e45f72e6d025ab3d
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.
27 from cmk.special_agents.agent_kubernetes import parse_frac_prefix
30 def parse_mul_prefix(value):
31 # type: (str) -> int
32 if value.endswith('k'):
33 return 1000 * int(value[:-1])
34 return int(value)
37 @get_parsed_item_data
38 def check_k8s_pods_memory(item, _no_params, metrics):
40 rss = 0
41 swap = 0
42 usage_bytes = 0
43 max_usage_bytes = 0
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)
53 yield check_levels(
54 usage_bytes, 'usage_bytes', _no_params, human_readable_func=get_bytes_human_readable)
55 yield check_levels(
56 max_usage_bytes,
57 'max_usage_bytes',
58 _no_params,
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'],
71 @get_parsed_item_data
72 def check_k8s_pods_cpu(item, _no_params, metrics):
74 system = 0
75 user = 0
76 usage = 0
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'],
97 @get_parsed_item_data
98 def check_k8s_pods_fs(item, _no_params, metrics):
100 inodes = 0
101 reads = 0
102 writes = 0
103 limit_bytes = 0
104 usage_bytes = 0
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)
116 yield check_levels(
117 limit_bytes, 'limit_bytes', _no_params, human_readable_func=get_bytes_human_readable)
118 yield check_levels(
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'],