Fix Linux cpu errors (#606)

Make the Linux cpu collector soft-error on missing `cpufreq` and
`thermal_throttle` features.
pull/609/head
Ben Kochie 9 years ago committed by GitHub
parent be6291adde
commit 182810056f
  1. 52
      collector/cpu_linux.go
  2. 5
      collector/fixtures/e2e-output.txt
  3. 1
      collector/fixtures/sys/bus/cpu/devices/cpu2/thermal_throttle/core_throttle_count
  4. 1
      collector/fixtures/sys/bus/cpu/devices/cpu2/thermal_throttle/package_throttle_count
  5. 1
      collector/fixtures/sys/bus/cpu/devices/cpu3/cpufreq/scaling_cur_freq
  6. 1
      collector/fixtures/sys/bus/cpu/devices/cpu3/cpufreq/scaling_max_freq
  7. 1
      collector/fixtures/sys/bus/cpu/devices/cpu3/cpufreq/scaling_min_freq

@ -17,9 +17,11 @@ package collector
import (
"fmt"
"os"
"path/filepath"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"github.com/prometheus/procfs"
)
@ -99,30 +101,38 @@ func (c *cpuCollector) updateCPUfreq(ch chan<- prometheus.Metric) error {
for _, cpu := range cpus {
_, cpuname := filepath.Split(cpu)
if value, err = readUintFromFile(filepath.Join(cpu, "cpufreq/scaling_cur_freq")); err != nil {
return err
if _, err := os.Stat(filepath.Join(cpu, "cpufreq")); os.IsNotExist(err) {
log.Debugf("CPU %q is missing cpufreq", cpu)
} else {
if value, err = readUintFromFile(filepath.Join(cpu, "cpufreq/scaling_cur_freq")); err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(c.cpuFreq, prometheus.GaugeValue, float64(value), cpuname)
if value, err = readUintFromFile(filepath.Join(cpu, "cpufreq/scaling_min_freq")); err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(c.cpuFreqMin, prometheus.GaugeValue, float64(value), cpuname)
if value, err = readUintFromFile(filepath.Join(cpu, "cpufreq/scaling_max_freq")); err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(c.cpuFreqMax, prometheus.GaugeValue, float64(value), cpuname)
}
ch <- prometheus.MustNewConstMetric(c.cpuFreq, prometheus.GaugeValue, float64(value), cpuname)
if value, err = readUintFromFile(filepath.Join(cpu, "cpufreq/scaling_min_freq")); err != nil {
return err
if _, err := os.Stat(filepath.Join(cpu, "thermal_throttle")); os.IsNotExist(err) {
log.Debugf("CPU %q is missing thermal_throttle", cpu)
} else {
if value, err = readUintFromFile(filepath.Join(cpu, "thermal_throttle/core_throttle_count")); err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(c.cpuCoreThrottle, prometheus.CounterValue, float64(value), cpuname)
if value, err = readUintFromFile(filepath.Join(cpu, "thermal_throttle/package_throttle_count")); err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(c.cpuPackageThrottle, prometheus.CounterValue, float64(value), cpuname)
}
ch <- prometheus.MustNewConstMetric(c.cpuFreqMin, prometheus.GaugeValue, float64(value), cpuname)
if value, err = readUintFromFile(filepath.Join(cpu, "cpufreq/scaling_max_freq")); err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(c.cpuFreqMax, prometheus.GaugeValue, float64(value), cpuname)
if value, err = readUintFromFile(filepath.Join(cpu, "thermal_throttle/core_throttle_count")); err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(c.cpuCoreThrottle, prometheus.CounterValue, float64(value), cpuname)
if value, err = readUintFromFile(filepath.Join(cpu, "thermal_throttle/package_throttle_count")); err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(c.cpuPackageThrottle, prometheus.CounterValue, float64(value), cpuname)
}
return nil

@ -212,22 +212,27 @@ node_cpu{cpu="cpu7",mode="user"} 290.98
# TYPE node_cpu_core_throttles_total counter
node_cpu_core_throttles_total{cpu="cpu0"} 5
node_cpu_core_throttles_total{cpu="cpu1"} 0
node_cpu_core_throttles_total{cpu="cpu2"} 40
# HELP node_cpu_frequency_hertz Current cpu thread frequency in hertz.
# TYPE node_cpu_frequency_hertz gauge
node_cpu_frequency_hertz{cpu="cpu0"} 1.699981e+06
node_cpu_frequency_hertz{cpu="cpu1"} 1.699981e+06
node_cpu_frequency_hertz{cpu="cpu3"} 8000
# HELP node_cpu_frequency_max_hertz Maximum cpu thread frequency in hertz.
# TYPE node_cpu_frequency_max_hertz gauge
node_cpu_frequency_max_hertz{cpu="cpu0"} 3.7e+06
node_cpu_frequency_max_hertz{cpu="cpu1"} 3.7e+06
node_cpu_frequency_max_hertz{cpu="cpu3"} 4.2e+06
# HELP node_cpu_frequency_min_hertz Minimum cpu thread frequency in hertz.
# TYPE node_cpu_frequency_min_hertz gauge
node_cpu_frequency_min_hertz{cpu="cpu0"} 800000
node_cpu_frequency_min_hertz{cpu="cpu1"} 800000
node_cpu_frequency_min_hertz{cpu="cpu3"} 1000
# HELP node_cpu_package_throttles_total Number of times this cpu package has been throttled.
# TYPE node_cpu_package_throttles_total counter
node_cpu_package_throttles_total{cpu="cpu0"} 30
node_cpu_package_throttles_total{cpu="cpu1"} 30
node_cpu_package_throttles_total{cpu="cpu2"} 6
# HELP node_disk_bytes_read The total number of bytes read successfully.
# TYPE node_disk_bytes_read counter
node_disk_bytes_read{device="dm-0"} 5.13708655616e+11

Loading…
Cancel
Save