From 4e1651f359d3f651918cc23e86c8f51fee2d4aa6 Mon Sep 17 00:00:00 2001 From: Danny Groenewegen Date: Tue, 1 Dec 2026 11:33:39 +0100 Subject: [PATCH] feat(alloy): make scrape/housekeeping interval configurable Alloy v1.22.0 added housekeeping_interval to the cadvisor exporter, which previously defaulted to 1s regardless of scrape interval, wasting CPU. Make it configurable via CADVISOR_HOUSEKEEPING_INTERVAL (default 60s), and the Prometheus scrape interval via PROMETHEUS_SCRAPE_INTERVAL (default 120s, unchanged). --- .env.sample | 5 +++++ abra.sh | 2 +- config.alloy.tmpl | 10 ++++++---- release/next | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 release/next diff --git a/.env.sample b/.env.sample index fc30d73..5cf15f8 100644 --- a/.env.sample +++ b/.env.sample @@ -23,6 +23,11 @@ SECRET_BASIC_AUTH_VERSION=v1 # Enable container filesystem usage metrics (expensive du-scan, ~30% CPU on large hosts) # CADVISOR_DISK_USAGE=1 +# How often metrics are sent to Prometheus, and how often cadvisor +# refreshes its container stats. Keep the second value lower than the first. +# PROMETHEUS_SCRAPE_INTERVAL=120s +# CADVISOR_HOUSEKEEPING_INTERVAL=60s + # Enable authenticated scraping of containers that opt in via # prometheus.io/auth=basic or prometheus.io/auth=bearer labels (used as # password/bearer token respectively). Insert it with: diff --git a/abra.sh b/abra.sh index c52f7ca..58fabf8 100644 --- a/abra.sh +++ b/abra.sh @@ -11,7 +11,7 @@ export MATRIX_ALERTMANAGER_CONFIG_VERSION=v2 export MATRIX_ALERTMANAGER_ENTRYPOINT_VERSION=v1 export GF_ALERTS_NODE_VERSION=v5 export GF_ALERTS_LOKI_VERSION=v5 -export CONFIG_ALLOY_VERSION=v4 +export CONFIG_ALLOY_VERSION=v5 export GF_ALERTS_TRAEFIK_VERSION=v1 # migrates secrets from old names to new names by reading values from the diff --git a/config.alloy.tmpl b/config.alloy.tmpl index f534ea7..f44e520 100644 --- a/config.alloy.tmpl +++ b/config.alloy.tmpl @@ -21,6 +21,8 @@ prometheus.exporter.cadvisor "docker" { {{ end }} // host-wide totals already come from prometheus.exporter.unix disable_root_cgroup_stats = true + housekeeping_interval = "{{ or (env "CADVISOR_HOUSEKEEPING_INTERVAL") "60s" }}" + max_housekeeping_interval = "{{ or (env "CADVISOR_HOUSEKEEPING_INTERVAL") "60s" }}" } prometheus.exporter.unix "default" { @@ -44,7 +46,7 @@ prometheus.exporter.unix "default" { prometheus.exporter.self "alloy" {} prometheus.scrape "default" { - scrape_interval = "120s" + scrape_interval = "{{ or (env "PROMETHEUS_SCRAPE_INTERVAL") "120s" }}" targets = array.concat( prometheus.exporter.self.alloy.targets, @@ -251,14 +253,14 @@ discovery.relabel "metrics_bearerauth" { } prometheus.scrape "containers" { - scrape_interval = "120s" + scrape_interval = "{{ or (env "PROMETHEUS_SCRAPE_INTERVAL") "120s" }}" targets = discovery.relabel.metrics_noauth.output forward_to = [prometheus.remote_write.prometheus.receiver] } {{ if ne (env "SECRET_SCRAPE_AUTH_VERSION") "" }} prometheus.scrape "containers_basicauth" { - scrape_interval = "120s" + scrape_interval = "{{ or (env "PROMETHEUS_SCRAPE_INTERVAL") "120s" }}" targets = discovery.relabel.metrics_basicauth.output forward_to = [prometheus.remote_write.prometheus.receiver] basic_auth { @@ -268,7 +270,7 @@ prometheus.scrape "containers_basicauth" { } prometheus.scrape "containers_bearerauth" { - scrape_interval = "120s" + scrape_interval = "{{ or (env "PROMETHEUS_SCRAPE_INTERVAL") "120s" }}" targets = discovery.relabel.metrics_bearerauth.output forward_to = [prometheus.remote_write.prometheus.receiver] bearer_token = "{{ secret "scrape_auth" }}" diff --git a/release/next b/release/next new file mode 100644 index 0000000..697a8c9 --- /dev/null +++ b/release/next @@ -0,0 +1 @@ +cadvisor's housekeeping interval now defaults to 60s (previously 1s regardless of scrape interval) and is configurable via the new CADVISOR_HOUSEKEEPING_INTERVAL env var; the Prometheus scrape interval is configurable too, via the new PROMETHEUS_SCRAPE_INTERVAL env var (default 120s, unchanged). -- 2.54.0