From aeba5f56db68fd158452866f794d80b64a13dbc8 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 21 May 2025 16:05:16 +0100 Subject: [PATCH] Scrape_configs: retain cAdvisor metrics for system processes Currently, CPU metrics for Kubelet, Containerd, etc. are dropped by a relabel rule since they don't have a container image. On most systems they run in their own cgroup called `system.slice`, so we can add another rule which uses that fact to give the `image` label a value and then they won't be dropped. --- prometheus/scrape_configs.libsonnet | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/prometheus/scrape_configs.libsonnet b/prometheus/scrape_configs.libsonnet index 4d6f6b446..5ddebae3f 100644 --- a/prometheus/scrape_configs.libsonnet +++ b/prometheus/scrape_configs.libsonnet @@ -255,6 +255,14 @@ ], metric_relabel_configs: [ + // Let system processes like kubelet survive the next rule by giving them a fake image. + { + source_labels: ['__name__', 'id'], + regex: 'container_([a-z_]+);/system.slice/(.+)', + target_label: 'image', + replacement: '$2', + }, + // Drop container_* metrics with no image. { source_labels: ['__name__', 'image'],