Module: check_mk
Branch: master
Commit: 7aab7e33a8f6323d43625a11452bcb574fbc573d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7aab7e33a8f632…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Sat Nov 24 14:19:45 2018 +0100
k8s_resources: add perfdata and metrics
CMK-511
Change-Id: I570ca14fb94c745c18309a72e008e0d573180ac4
---
checks/k8s_resources | 27 +++---
cmk/gui/plugins/metrics/check_mk.py | 97 ++++++++++++++++++++++
.../datasets/k8s_resources_regression.py | 20 ++---
3 files changed, 123 insertions(+), 21 deletions(-)
diff --git a/checks/k8s_resources b/checks/k8s_resources
index 705eef7..a9a3127 100644
--- a/checks/k8s_resources
+++ b/checks/k8s_resources
@@ -42,19 +42,20 @@ def inventory_k8s_pod_resources(parsed):
def check_k8s_pod_resources(_no_item, _no_params, parsed):
pods = parsed.get('allocations', {}).get('pods', 0)
- yield 0, 'Pods: %d' % pods
+ yield 0, 'Pods: %d' % pods, [('k8s_pods', pods)]
allocatable = parsed.get('allocatable', {}).get('pods', 0)
- yield 0, 'Allocatable: %d' % allocatable
+ yield 0, 'Allocatable: %d' % allocatable, [('k8s_pods_allocatable',
allocatable)]
capacity = parsed.get('capacity', {}).get('pods', 0)
- yield 0, 'Capacity: %d' % capacity
+ yield 0, 'Capacity: %d' % capacity, [('k8s_pods_capacity',
capacity)]
check_info['k8s_resources.pods'] = {
'inventory_function': inventory_k8s_pod_resources,
'check_function': check_k8s_pod_resources,
'service_description': 'Pod resources',
+ 'has_perfdata': True,
}
@@ -65,25 +66,26 @@ def inventory_k8s_cpu_resources(parsed):
def check_k8s_cpu_resources(_no_item, _no_params, parsed):
request = parsed.get('requests', {}).get('cpu', 0.0)
- yield 0, 'Request: %.3f' % request
+ yield 0, 'Request: %.3f' % request, [('k8s_cpu_request', request)]
limit = parsed.get('limits', {}).get('cpu')
if math.isinf(limit):
yield 0, 'Limit: n.a.'
else:
- yield 0, 'Limit: %.3f' % limit
+ yield 0, 'Limit: %.3f' % limit, [('k8s_cpu_limit', limit)]
allocatable = parsed.get('allocatable', {}).get('cpu', 0.0)
- yield 0, 'Allocatable: %.3f' % allocatable
+ yield 0, 'Allocatable: %.3f' % allocatable, [('k8s_cpu_allocatable',
allocatable)]
capacity = parsed.get('capacity', {}).get('cpu', 0.0)
- yield 0, 'Capacity: %.3f' % capacity
+ yield 0, 'Capacity: %.3f' % capacity, [('k8s_cpu_capacity',
capacity)]
check_info['k8s_resources.cpu'] = {
'inventory_function': inventory_k8s_cpu_resources,
'check_function': check_k8s_cpu_resources,
'service_description': 'CPU resources',
+ 'has_perfdata': True,
}
@@ -94,23 +96,26 @@ def inventory_k8s_mem_resources(parsed):
def check_k8s_mem_resources(_no_item, _no_params, parsed):
request = parsed.get('requests', {}).get('memory', 0.0)
- yield 0, 'Request: %s' % get_bytes_human_readable(request)
+ yield 0, 'Request: %s' % get_bytes_human_readable(request),
[('k8s_memory_request', request)]
limit = parsed.get('limits', {}).get('memory')
if math.isinf(limit):
yield 0, 'Limit: n.a.'
else:
- yield 0, 'Limit: %s' % get_bytes_human_readable(limit)
+ yield 0, 'Limit: %s' % get_bytes_human_readable(limit),
[('k8s_memory_limit', limit)]
allocatable = parsed.get('allocatable', {}).get('memory', 0.0)
- yield 0, 'Allocatable: %s' % get_bytes_human_readable(allocatable)
+ yield 0, 'Allocatable: %s' % get_bytes_human_readable(allocatable),
[('k8s_memory_allocatable',
+ allocatable)]
capacity = parsed.get('capacity', {}).get('memory', 0.0)
- yield 0, 'Capacity: %s' % get_bytes_human_readable(capacity)
+ yield 0, 'Capacity: %s' % get_bytes_human_readable(capacity),
[('k8s_memory_capacity',
+ capacity)]
check_info['k8s_resources.memory'] = {
'inventory_function': inventory_k8s_mem_resources,
'check_function': check_k8s_mem_resources,
'service_description': 'Memory resources',
+ 'has_perfdata': True
}
diff --git a/cmk/gui/plugins/metrics/check_mk.py b/cmk/gui/plugins/metrics/check_mk.py
index 452e272..b97dd37 100644
--- a/cmk/gui/plugins/metrics/check_mk.py
+++ b/cmk/gui/plugins/metrics/check_mk.py
@@ -4369,6 +4369,72 @@ metric_info["k8s_nodes"] = {
"color": "11/a",
}
+metric_info["k8s_pods"] = {
+ "title": _("Pods"),
+ "unit": "count",
+ "color": "16/b",
+}
+
+metric_info["k8s_pods_allocatable"] = {
+ "title": _("Allocatable"),
+ "unit": "count",
+ "color": "#e0e0e0",
+}
+
+metric_info["k8s_pods_capacity"] = {
+ "title": _("Capacity"),
+ "unit": "count",
+ "color": "c0c0c0",
+}
+
+metric_info["k8s_cpu_request"] = {
+ "title": _("Request"),
+ "unit": "",
+ "color": "26/b",
+}
+
+metric_info["k8s_cpu_limit"] = {
+ "title": _("Limit"),
+ "unit": "",
+ "color": "26/a",
+}
+
+metric_info["k8s_cpu_allocatable"] = {
+ "title": _("Allocatable"),
+ "unit": "",
+ "color": "#e0e0e0",
+}
+
+metric_info["k8s_cpu_capacity"] = {
+ "title": _("Capacity"),
+ "unit": "",
+ "color": "#c0c0c0",
+}
+
+metric_info["k8s_memory_request"] = {
+ "title": _("Request"),
+ "unit": "bytes",
+ "color": "42/b",
+}
+
+metric_info["k8s_memory_limit"] = {
+ "title": _("Limit"),
+ "unit": "bytes",
+ "color": "42/a",
+}
+
+metric_info["k8s_memory_allocatable"] = {
+ "title": _("Allocatable"),
+ "unit": "bytes",
+ "color": "#e0e0e0",
+}
+
+metric_info["k8s_memory_capacity"] = {
+ "title": _("Capacity"),
+ "unit": "bytes",
+ "color": "#c0c0c0",
+}
+
metric_info["active_vms"] = {
"title": _("Active VMs"),
"unit": "count",
@@ -8060,6 +8126,37 @@ graph_info["citrix_serverload"] = {
"range": (0, 100),
}
+graph_info["k8s_resources.pods"] = {
+ "title": _("Pods"),
+ "metrics": [
+ ("k8s_pods_capacity", "area"),
+ ("k8s_pods_allocatable", "area"),
+ ("k8s_pods", "area"),
+ ],
+}
+
+graph_info["k8s_resources.cpu"] = {
+ "title": _("CPU"),
+ "metrics": [
+ ("k8s_cpu_capacity", "area"),
+ ("k8s_cpu_allocatable", "area"),
+ ("k8s_cpu_limit", "area"),
+ ("k8s_cpu_request", "area"),
+ ],
+ "optional_metrics": ["k8s_cpu_limit"],
+}
+
+graph_info["k8s_resources.memory"] = {
+ "title": _("Memory"),
+ "metrics": [
+ ("k8s_memory_capacity", "area"),
+ ("k8s_memory_allocatable", "area"),
+ ("k8s_memory_limit", "area"),
+ ("k8s_memory_request", "area"),
+ ],
+ "optional_metrics": ["k8s_memory_limit"],
+}
+
graph_info["used_cpu_time"] = {
"title": _("Used CPU Time"),
"metrics": [
diff --git a/tests/unit/checks/generictests/datasets/k8s_resources_regression.py
b/tests/unit/checks/generictests/datasets/k8s_resources_regression.py
index ee81cf3..df75a4d 100644
--- a/tests/unit/checks/generictests/datasets/k8s_resources_regression.py
+++ b/tests/unit/checks/generictests/datasets/k8s_resources_regression.py
@@ -12,20 +12,20 @@ discovery = {
checks = {
'cpu': [(None, 'default', [
- (0, 'Request: 0.200', []),
- (0, 'Limit: 0.500', []),
- (0, 'Allocatable: 0.940', []),
- (0, 'Capacity: 1.000', []),
+ (0, 'Request: 0.200', [('k8s_cpu_request', 0.2)]),
+ (0, 'Limit: 0.500', [('k8s_cpu_limit', 0.5)]),
+ (0, 'Allocatable: 0.940', [('k8s_cpu_allocatable',
0.9400000000000001)]),
+ (0, 'Capacity: 1.000', [('k8s_cpu_capacity', 1.0)]),
])],
'memory': [(None, 'default', [
- (0, 'Request: 0.00 B', []),
+ (0, 'Request: 0.00 B', [('k8s_memory_request', 0.0)]),
(0, 'Limit: n.a.', []),
- (0, 'Allocatable: 581.59 MB', []),
- (0, 'Capacity: 581.59 MB', []),
+ (0, 'Allocatable: 581.59 MB', [('k8s_memory_allocatable',
609845248.0)]),
+ (0, 'Capacity: 581.59 MB', [('k8s_memory_capacity',
609845248.0)]),
])],
'pods': [(None, 'default', [
- (0, 'Pods: 0', []),
- (0, 'Allocatable: 110', []),
- (0, 'Capacity: 110', []),
+ (0, 'Pods: 0', [('k8s_pods', 0)]),
+ (0, 'Allocatable: 110', [('k8s_pods_allocatable', 110)]),
+ (0, 'Capacity: 110', [('k8s_pods_capacity', 110)]),
])],
}