diff --git a/CHANGELOG.md b/CHANGELOG.md index 0427b518..b60da3c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,8 +24,9 @@ * [BUGFIX] Renamed label `state` to `name` on `node_systemd_service_restart_total`. #1393 * [BUGFIX] Fix netdev nil reference on Darwin #1414 * [BUGFIX] Strip path.rootfs from mountpoint labels #1421 -* [FEATURE] Add new thermal_zone collector #1425 * [BUGFIX] Fix empty string in path.rootfs #1464 +* [FEATURE] Add new thermal_zone collector #1425 +* [FEATURE] Add new cooling_device metrics to thermal zone collector #1445 ## 0.18.1 / 2019-06-04 diff --git a/README.md b/README.md index f38bcd01..7a4b9f40 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ schedstat | Exposes task scheduler statistics from `/proc/schedstat`. | Linux sockstat | Exposes various statistics from `/proc/net/sockstat`. | Linux stat | Exposes various statistics from `/proc/stat`. This includes boot time, forks and interrupts. | Linux textfile | Exposes statistics read from local disk. The `--collector.textfile.directory` flag must be set. | _any_ +thermal\_zone | Exposes thermal zone & cooling device statistics from `/sys/class/thermal`. | Linux time | Exposes the current system time. | _any_ timex | Exposes selected adjtimex(2) system call stats. | Linux uname | Exposes system information as provided by the uname system call. | Darwin, FreeBSD, Linux, OpenBSD diff --git a/collector/fixtures/e2e-64k-page-output.txt b/collector/fixtures/e2e-64k-page-output.txt index 2737a01c..6b2e6bd2 100644 --- a/collector/fixtures/e2e-64k-page-output.txt +++ b/collector/fixtures/e2e-64k-page-output.txt @@ -178,6 +178,12 @@ node_buddyinfo_blocks{node="0",size="9",zone="Normal"} 0 # HELP node_context_switches_total Total number of context switches. # TYPE node_context_switches_total counter node_context_switches_total 3.8014093e+07 +# HELP node_cooling_device_cur_state Current throttle state of the cooling device +# TYPE node_cooling_device_cur_state gauge +node_cooling_device_cur_state{name="0",type="Processor"} 0 +# HELP node_cooling_device_max_state Maximum throttle state of the cooling device +# TYPE node_cooling_device_max_state gauge +node_cooling_device_max_state{name="0",type="Processor"} 3 # HELP node_cpu_core_throttles_total Number of times this cpu core has been throttled. # TYPE node_cpu_core_throttles_total counter node_cpu_core_throttles_total{core="0",package="0"} 5 diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index 0a3291dc..7651f53b 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -178,6 +178,12 @@ node_buddyinfo_blocks{node="0",size="9",zone="Normal"} 0 # HELP node_context_switches_total Total number of context switches. # TYPE node_context_switches_total counter node_context_switches_total 3.8014093e+07 +# HELP node_cooling_device_cur_state Current throttle state of the cooling device +# TYPE node_cooling_device_cur_state gauge +node_cooling_device_cur_state{name="0",type="Processor"} 0 +# HELP node_cooling_device_max_state Maximum throttle state of the cooling device +# TYPE node_cooling_device_max_state gauge +node_cooling_device_max_state{name="0",type="Processor"} 3 # HELP node_cpu_core_throttles_total Number of times this cpu core has been throttled. # TYPE node_cpu_core_throttles_total counter node_cpu_core_throttles_total{core="0",package="0"} 5 diff --git a/collector/fixtures/sys.ttar b/collector/fixtures/sys.ttar index 2880390e..41e062da 100644 --- a/collector/fixtures/sys.ttar +++ b/collector/fixtures/sys.ttar @@ -926,6 +926,9 @@ Mode: 755 Path: sys/class/thermal/thermal_zone0 SymlinkTo: ../../devices/virtual/thermal/thermal_zone0 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: sys/class/thermal/cooling_device0 +SymlinkTo: ../../devices/virtual/thermal/cooling_device0 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Directory: sys/devices Mode: 755 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2472,6 +2475,24 @@ Mode: 755 Directory: sys/devices/virtual/thermal Mode: 755 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Directory: sys/devices/virtual/thermal/cooling_device0 +Mode: 755 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: sys/devices/virtual/thermal/cooling_device0/cur_state +Lines: 1 +0 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: sys/devices/virtual/thermal/cooling_device0/max_state +Lines: 1 +3 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: sys/devices/virtual/thermal/cooling_device0/type +Lines: 1 +Processor +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Directory: sys/devices/virtual/thermal/thermal_zone0 Mode: 755 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/collector/thermal_zone_linux.go b/collector/thermal_zone_linux.go index 16fe61c6..13606daa 100644 --- a/collector/thermal_zone_linux.go +++ b/collector/thermal_zone_linux.go @@ -22,9 +22,14 @@ import ( "github.com/prometheus/procfs/sysfs" ) +const coolingDevice = "cooling_device" +const thermalZone = "thermal_zone" + type thermalZoneCollector struct { - fs sysfs.FS - zoneTemp *prometheus.Desc + fs sysfs.FS + coolingDeviceCurState *prometheus.Desc + coolingDeviceMaxState *prometheus.Desc + zoneTemp *prometheus.Desc } func init() { @@ -41,10 +46,20 @@ func NewThermalZoneCollector() (Collector, error) { return &thermalZoneCollector{ fs: fs, zoneTemp: prometheus.NewDesc( - prometheus.BuildFQName(namespace, "thermal_zone", "temp"), + prometheus.BuildFQName(namespace, thermalZone, "temp"), "Zone temperature in Celsius", []string{"zone", "type"}, nil, ), + coolingDeviceCurState: prometheus.NewDesc( + prometheus.BuildFQName(namespace, coolingDevice, "cur_state"), + "Current throttle state of the cooling device", + []string{"name", "type"}, nil, + ), + coolingDeviceMaxState: prometheus.NewDesc( + prometheus.BuildFQName(namespace, coolingDevice, "max_state"), + "Maximum throttle state of the cooling device", + []string{"name", "type"}, nil, + ), }, nil } @@ -64,5 +79,28 @@ func (c *thermalZoneCollector) Update(ch chan<- prometheus.Metric) error { ) } + coolingDevices, err := c.fs.ClassCoolingDeviceStats() + if err != nil { + return err + } + + for _, stats := range coolingDevices { + ch <- prometheus.MustNewConstMetric( + c.coolingDeviceCurState, + prometheus.GaugeValue, + float64(stats.CurState), + stats.Name, + stats.Type, + ) + + ch <- prometheus.MustNewConstMetric( + c.coolingDeviceMaxState, + prometheus.GaugeValue, + float64(stats.MaxState), + stats.Name, + stats.Type, + ) + } + return nil }