Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions collector/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,13 @@ func (c *cpuCollector) updateInfo(ch chan<- prometheus.Metric) error {
cpu.CacheSize)
}

cpuFreqEnabled, ok := collectorState["cpufreq"]
if !ok || cpuFreqEnabled == nil {
c.logger.Debug("cpufreq key missing or nil value in collectorState map")
} else if *cpuFreqEnabled {
for _, cpu := range info {
ch <- prometheus.MustNewConstMetric(c.cpuFrequencyHz,
prometheus.GaugeValue,
cpu.CPUMHz*1e6,
cpu.PhysicalID,
cpu.CoreID,
strconv.Itoa(int(cpu.Processor)))
}
for _, cpu := range info {
ch <- prometheus.MustNewConstMetric(c.cpuFrequencyHz,
prometheus.GaugeValue,
cpu.CPUMHz*1e6,
cpu.PhysicalID,
cpu.CoreID,
strconv.Itoa(int(cpu.Processor)))
}

if len(info) != 0 {
Expand Down
13 changes: 12 additions & 1 deletion collector/cpufreq_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,21 @@ func (c *cpuFreqCollector) Update(ch chan<- prometheus.Metric) error {
return err
}

// The current frequency metric is also provided by the cpuinfo-based collector.
// If that collector is enabled and set to provide frequency information,
// we skip this metric here (otherwise the two collectors would race for it)
cpuCollectorEnabled, ok := collectorState["cpu"]
skipCurrentFreq := false
if !ok || cpuCollectorEnabled == nil {
c.logger.Debug("cpu key missing or nil value in collectorState map")
} else {
skipCurrentFreq = *cpuCollectorEnabled && *enableCPUInfo
}

// sysfs cpufreq values are kHz, thus multiply by 1000 to export base units (hz).
// See https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt
for _, stats := range cpuFreqs {
if stats.CpuinfoCurrentFrequency != nil {
if stats.CpuinfoCurrentFrequency != nil && !skipCurrentFreq {
ch <- prometheus.MustNewConstMetric(
cpuFreqHertzDesc,
prometheus.GaugeValue,
Expand Down
Loading