mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-28 06:59:44 -08:00
Fix Linux cpu errors (#606)
Make the Linux cpu collector soft-error on missing `cpufreq` and `thermal_throttle` features.
This commit is contained in:
parent
be6291adde
commit
182810056f
|
@ -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
|
||||
}
|
||||
ch <- prometheus.MustNewConstMetric(c.cpuFreq, prometheus.GaugeValue, float64(value), cpuname)
|
||||
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_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
|
||||
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.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 _, 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
|
||||
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.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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
40
|
|
@ -0,0 +1 @@
|
|||
6
|
|
@ -0,0 +1 @@
|
|||
8000
|
|
@ -0,0 +1 @@
|
|||
4200000
|
|
@ -0,0 +1 @@
|
|||
1000
|
Loading…
Reference in a new issue