Module: check_mk
Branch: master
Commit: f08722ff76c02f0f32266357369371583f28ffff
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f08722ff76c02f…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Sat Nov 24 13:32:31 2018 +0100
k8s_resources: now returns n.a. limits
If at least one container on a node does not specify CPU or memory
limits the check now returns "Limit: unbound" since the container
may consume any amound of resources on that node.
CMK-511
Change-Id: I15db41ea125fa5ea6a723e7afbf2a30e21e06aad
---
agents/special/agent_kubernetes | 13 +++++++++++--
checkman/k8s_resources.cpu | 7 +++++--
checkman/k8s_resources.memory | 7 +++++--
checks/k8s_resources | 8 ++++++--
.../generictests/datasets/k8s_resources_regression.py | 3 ++-
5 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/agents/special/agent_kubernetes b/agents/special/agent_kubernetes
index 79c3da6..5936d3a 100755
--- a/agents/special/agent_kubernetes
+++ b/agents/special/agent_kubernetes
@@ -221,6 +221,11 @@ class Pods(object):
return view
def resources_per_node(self):
+ """
+ Returns the limits and requests of all containers grouped by node. If at least
+ one container does not specify a limit, infinity is returned as the container
+ may consume any amount of resources.
+ """
# TODO: add annotation from below and fix parse_cpu and parse_memory
view = {} # type: Dict[str, Dict[str, Dict[str, Optional[float]]]]
for pod in self.items:
@@ -241,9 +246,13 @@ class Pods(object):
if resources:
limits = resources.limits
if limits:
- node_data['limits']['cpu'] +=
parse_cpu(limits.get('cpu', '0.0'))
+ node_data['limits']['cpu'] +=
parse_cpu(limits.get('cpu', 'inf'))
node_data['limits']['memory'] +=
parse_memory(
- limits.get('memory', '0.0'))
+ limits.get('memory', 'inf'))
+ else:
+ node_data['limits']['cpu'] +=
float('inf')
+ node_data['limits']['memory'] +=
float('inf')
+
requests = resources.requests
if requests:
node_data['requests']['cpu'] +=
parse_cpu(requests.get('cpu', '0.0'))
diff --git a/checkman/k8s_resources.cpu b/checkman/k8s_resources.cpu
index a1b14a0..5442cce 100644
--- a/checkman/k8s_resources.cpu
+++ b/checkman/k8s_resources.cpu
@@ -4,8 +4,11 @@ catalog: app/kubernetes
license: GPL
distribution: check_mk
description:
- This check monitors the CPU resources of a Kubernetes node.
- It always returns {OK}.
+ This check monitors the requested CPU as well as the CPU limits and capacity of
+ a Kubernetes node. If at least one container running on a node does not specify
+ limits, the node has no applicable limits.
+
+ The check always returns {OK}.
inventory:
One service is created.
\ No newline at end of file
diff --git a/checkman/k8s_resources.memory b/checkman/k8s_resources.memory
index 2549d74..3da7fea 100644
--- a/checkman/k8s_resources.memory
+++ b/checkman/k8s_resources.memory
@@ -4,8 +4,11 @@ catalog: app/kubernetes
license: GPL
distribution: check_mk
description:
- This check monitors the memory resources of a Kubernetes node.
- It always returns {OK}.
+ This check monitors the requested memory as well as the memory limits and capacity
+ of a Kubernetes node. If at least one container running on a node does not specify
+ limits, the node has no applicable limits.
+
+ The check always returns {OK}.
inventory:
One service is created.
\ No newline at end of file
diff --git a/checks/k8s_resources b/checks/k8s_resources
index 826e24e..7913b38 100644
--- a/checks/k8s_resources
+++ b/checks/k8s_resources
@@ -65,7 +65,9 @@ def check_k8s_cpu_resources(_no_item, _no_params, parsed):
yield 0, 'Request: %.3f' % request
limit = parsed.get('limits', {}).get('cpu')
- if limit:
+ if math.isinf(limit):
+ yield 0, 'Limit: n.a.'
+ else:
yield 0, 'Limit: %.3f' % limit
capacity = parsed.get('capacity', {}).get('cpu', 0.0)
@@ -89,7 +91,9 @@ def check_k8s_mem_resources(_no_item, _no_params, parsed):
yield 0, 'Request: %s' % get_bytes_human_readable(request)
limit = parsed.get('limits', {}).get('memory')
- if limit:
+ if math.isinf(limit):
+ yield 0, 'Limit: n.a.'
+ else:
yield 0, 'Limit: %s' % get_bytes_human_readable(limit)
capacity = parsed.get('capacity', {}).get('memory', 0.0)
diff --git a/tests/unit/checks/generictests/datasets/k8s_resources_regression.py
b/tests/unit/checks/generictests/datasets/k8s_resources_regression.py
index be6f4e6..dc1e039 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":
0.0}, "allocations": {}}'
+ u'{"capacity": {"pods": 110, "cpu": 1.0,
"memory": 609845248.0}, "requests": {"cpu": 0.2,
"memory": 0.0}, "limits": {"cpu": 0.5, "memory":
Infinity}, "allocations": {}}'
]]
discovery = {
@@ -18,6 +18,7 @@ checks = {
])],
'memory': [(None, 'default', [
(0, 'Request: 0.00 B', []),
+ (0, 'Limit: n.a.', []),
(0, 'Capacity: 581.59 MB', []),
])],
'pods': [(None, 'default', [