Module: check_mk
Branch: master
Commit: 484dfc9468b1867cd4cbc4c6be1b13ee151c5553
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=484dfc9468b186…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Sat Nov 24 14:12:46 2018 +0100
k8s_resources: additionally return allocatable Pods, CPU and memory
CMK-511
Change-Id: Ia8549b57e187b1b9ce626afbf074078550253708
---
agents/special/agent_kubernetes | 7 +++++++
checks/k8s_resources | 11 ++++++++++-
.../checks/generictests/datasets/k8s_resources_regression.py | 5 ++++-
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/agents/special/agent_kubernetes b/agents/special/agent_kubernetes
index 5936d3a..fd4656d 100755
--- a/agents/special/agent_kubernetes
+++ b/agents/special/agent_kubernetes
@@ -182,6 +182,13 @@ class Nodes(object):
'memory': parse_memory(capacity.get('memory')),
'pods': parse_int(capacity.get('pods')),
}
+ allocatable = status.allocatable
+ if allocatable:
+ node_data['allocatable'] = {
+ 'cpu': parse_cpu(allocatable.get('cpu')),
+ 'memory':
parse_memory(allocatable.get('memory')),
+ 'pods': parse_int(allocatable.get('pods')),
+ }
view[node.metadata.name] = node_data
return view
diff --git a/checks/k8s_resources b/checks/k8s_resources
index 7913b38..705eef7 100644
--- a/checks/k8s_resources
+++ b/checks/k8s_resources
@@ -44,8 +44,11 @@ def check_k8s_pod_resources(_no_item, _no_params, parsed):
pods = parsed.get('allocations', {}).get('pods', 0)
yield 0, 'Pods: %d' % pods
+ allocatable = parsed.get('allocatable', {}).get('pods', 0)
+ yield 0, 'Allocatable: %d' % allocatable
+
capacity = parsed.get('capacity', {}).get('pods', 0)
- yield 0, 'Capacity: %s' % capacity
+ yield 0, 'Capacity: %d' % capacity
check_info['k8s_resources.pods'] = {
@@ -70,6 +73,9 @@ def check_k8s_cpu_resources(_no_item, _no_params, parsed):
else:
yield 0, 'Limit: %.3f' % limit
+ allocatable = parsed.get('allocatable', {}).get('cpu', 0.0)
+ yield 0, 'Allocatable: %.3f' % allocatable
+
capacity = parsed.get('capacity', {}).get('cpu', 0.0)
yield 0, 'Capacity: %.3f' % capacity
@@ -96,6 +102,9 @@ def check_k8s_mem_resources(_no_item, _no_params, parsed):
else:
yield 0, 'Limit: %s' % get_bytes_human_readable(limit)
+ allocatable = parsed.get('allocatable', {}).get('memory', 0.0)
+ yield 0, 'Allocatable: %s' % get_bytes_human_readable(allocatable)
+
capacity = parsed.get('capacity', {}).get('memory', 0.0)
yield 0, 'Capacity: %s' % get_bytes_human_readable(capacity)
diff --git a/tests/unit/checks/generictests/datasets/k8s_resources_regression.py
b/tests/unit/checks/generictests/datasets/k8s_resources_regression.py
index dc1e039..ee81cf3 100644
--- a/tests/unit/checks/generictests/datasets/k8s_resources_regression.py
+++ b/tests/unit/checks/generictests/datasets/k8s_resources_regression.py
@@ -1,7 +1,7 @@
checkname = 'k8s_resources'
info = [[
- u'{"capacity": {"pods": 110, "cpu": 1.0,
"memory": 609845248.0}, "requests": {"cpu": 0.2,
"memory": 0.0}, "limits": {"cpu": 0.5, "memory":
Infinity}, "allocations": {}}'
+ u'{"allocatable": {"pods": 110, "cpu":
0.9400000000000001, "memory": 609845248.0}, "capacity":
{"pods": 110, "cpu": 1.0, "memory": 609845248.0},
"requests": {"cpu": 0.2, "memory": 0.0}, "limits":
{"cpu": 0.5, "memory": Infinity}, "allocations": {}}'
]]
discovery = {
@@ -14,15 +14,18 @@ checks = {
'cpu': [(None, 'default', [
(0, 'Request: 0.200', []),
(0, 'Limit: 0.500', []),
+ (0, 'Allocatable: 0.940', []),
(0, 'Capacity: 1.000', []),
])],
'memory': [(None, 'default', [
(0, 'Request: 0.00 B', []),
(0, 'Limit: n.a.', []),
+ (0, 'Allocatable: 581.59 MB', []),
(0, 'Capacity: 581.59 MB', []),
])],
'pods': [(None, 'default', [
(0, 'Pods: 0', []),
+ (0, 'Allocatable: 110', []),
(0, 'Capacity: 110', []),
])],
}