From b941a24e27742bf93ddf40b054aed854cad0e0ab Mon Sep 17 00:00:00 2001 From: Dean Chen <862469039@qq.com> Date: Mon, 20 Jul 2026 23:33:18 +0500 Subject: [PATCH] collector/cpu: avoid frequency_hertz clash with cpufreq Both collectors export node_cpu_frequency_hertz, but with different help text and labels. When cpu.info and cpufreq run together (the common case), Prometheus gather fails with inconsistent help strings. Only fall back to /proc/cpuinfo when the cpufreq collector is disabled. Drop the overlapping samples from the e2e fixture. Fixes #3689 Signed-off-by: Dean Chen <862469039@qq.com> --- collector/cpu_linux.go | 5 ++++- collector/fixtures/e2e-output.txt | 10 ---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/collector/cpu_linux.go b/collector/cpu_linux.go index f7b0c3ef1f..780edaa1a4 100644 --- a/collector/cpu_linux.go +++ b/collector/cpu_linux.go @@ -219,10 +219,13 @@ func (c *cpuCollector) updateInfo(ch chan<- prometheus.Metric) error { cpu.CacheSize) } + // Avoid clashing with the cpufreq collector, which exports the same + // metric name with a different help string and label set. Only use + // /proc/cpuinfo when cpufreq is disabled. cpuFreqEnabled, ok := collectorState["cpufreq"] if !ok || cpuFreqEnabled == nil { c.logger.Debug("cpufreq key missing or nil value in collectorState map") - } else if *cpuFreqEnabled { + } else if !*cpuFreqEnabled { for _, cpu := range info { ch <- prometheus.MustNewConstMetric(c.cpuFrequencyHz, prometheus.GaugeValue, diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index 141cb76c3a..5709dd51dd 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -902,16 +902,6 @@ node_cpu_flag_info{flag="aes"} 1 node_cpu_flag_info{flag="avx"} 1 node_cpu_flag_info{flag="avx2"} 1 node_cpu_flag_info{flag="constant_tsc"} 1 -# HELP node_cpu_frequency_hertz CPU frequency in hertz from /proc/cpuinfo. -# TYPE node_cpu_frequency_hertz gauge -node_cpu_frequency_hertz{core="0",cpu="0",package="0"} 7.99998e+08 -node_cpu_frequency_hertz{core="0",cpu="4",package="0"} 7.99989e+08 -node_cpu_frequency_hertz{core="1",cpu="1",package="0"} 8.00037e+08 -node_cpu_frequency_hertz{core="1",cpu="5",package="0"} 8.00083e+08 -node_cpu_frequency_hertz{core="2",cpu="2",package="0"} 8.0001e+08 -node_cpu_frequency_hertz{core="2",cpu="6",package="0"} 8.00017e+08 -node_cpu_frequency_hertz{core="3",cpu="3",package="0"} 8.00028e+08 -node_cpu_frequency_hertz{core="3",cpu="7",package="0"} 8.0003e+08 # HELP node_cpu_guest_seconds_total Seconds the CPUs spent in guests (VMs) for each mode. # TYPE node_cpu_guest_seconds_total counter node_cpu_guest_seconds_total{cpu="0",mode="nice"} 0.01