Module: check_mk
Branch: master
Commit: f15b70255ed45df0a7aa3703daf5181315d10ef9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f15b70255ed45d…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Tue Mar 26 09:55:57 2019 +0100
k8s_pod_container: return CRIT if not all Containers are ready
CMK-1893
Change-Id: Ia56aef5bed5cc405cf43237193bde07e26387533
---
checkman/k8s_pod_container | 5 +++++
checks/k8s_pod_container | 10 +++++++---
cmk/gui/plugins/metrics/check_mk.py | 8 ++++++++
.../generictests/datasets/k8s_pod_container_regression.py | 6 ++----
4 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/checkman/k8s_pod_container b/checkman/k8s_pod_container
index a2ec51d..c501cae 100644
--- a/checkman/k8s_pod_container
+++ b/checkman/k8s_pod_container
@@ -8,6 +8,11 @@ description:
ready containers of a pod. A container is ready if it
passes its readiness probe.
+ To account for the initial setup of the container or the
+ switch of a Pod from one to another the ruleset
+ {Maximum number of check attempts for service} should be
+ used.
+
item:
No item.
diff --git a/checks/k8s_pod_container b/checks/k8s_pod_container
index 601e256..fa6e4a2 100644
--- a/checks/k8s_pod_container
+++ b/checks/k8s_pod_container
@@ -31,10 +31,14 @@ def inventory_k8s_pod_container(parsed):
def check_k8s_pod_container(_no_item, params, parsed):
container = len(parsed)
- yield 0, "Container: %d" % container, [('docker_all_containers',
container)]
-
ready = sum(container['ready'] for container in parsed.itervalues())
- yield 0, "Ready: %d" % ready, [('ready_containers', ready)]
+
+ state = 2 if ready != container else 0
+ perfdata = [
+ ('docker_all_containers', container, None, None, 0, container),
+ ('ready_containers', ready, None, None, 0, container),
+ ]
+ yield state, "Ready: %d/%d" % (ready, container), perfdata
check_info['k8s_pod_container'] = {
diff --git a/cmk/gui/plugins/metrics/check_mk.py b/cmk/gui/plugins/metrics/check_mk.py
index 15f5ee7..78630d9 100644
--- a/cmk/gui/plugins/metrics/check_mk.py
+++ b/cmk/gui/plugins/metrics/check_mk.py
@@ -8949,6 +8949,14 @@ graph_info["k8s_resources.memory"] = {
"optional_metrics": ["k8s_memory_capacity",
"k8s_memory_allocatable", "k8s_memory_limit"],
}
+graph_info["k8s_pod_container"] = {
+ "title": _("Ready containers"),
+ "metrics": [
+ ("docker_all_containers", "line"),
+ ("ready_containers", "area"),
+ ],
+}
+
graph_info["used_cpu_time"] = {
"title": _("Used CPU Time"),
"metrics": [
diff --git a/tests/unit/checks/generictests/datasets/k8s_pod_container_regression.py
b/tests/unit/checks/generictests/datasets/k8s_pod_container_regression.py
index d8a79e9..4d6c45a 100644
--- a/tests/unit/checks/generictests/datasets/k8s_pod_container_regression.py
+++ b/tests/unit/checks/generictests/datasets/k8s_pod_container_regression.py
@@ -12,7 +12,5 @@ discovery = {'': [(None, {})]}
checks = {'': [(None,
{},
- [(0,
- 'Container: 1',
- [('docker_all_containers', 1, None, None, None, None)]),
- (0, 'Ready: 1', [('ready_containers', 1, None, None,
None, None)])])]}
\ No newline at end of file
+ [(0, 'Ready: 1/1', [('docker_all_containers', 1, None,
None, 0, 1),
+ ('ready_containers', 1, None, None, 0,
1)])])]}