Skip to content

Commit

Permalink
Scrape cooling_device state
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Schmitz <[email protected]>
  • Loading branch information
Alex Schmitz authored and davemcphee committed Aug 30, 2019
1 parent d3478a2 commit 664025d
Show file tree
Hide file tree
Showing 11 changed files with 557 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* [BUGFIX] Fix netdev nil reference on Darwin #1414
* [BUGFIX] Strip path.rootfs from mountpoint labels #1421
* [FEATURE] Add new thermal_zone collector #1425
* [FEATURE] Add new cooling_device metrics to thermal zone collector #1445

## 0.18.1 / 2019-06-04

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions collector/fixtures/e2e-64k-page-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions collector/fixtures/e2e-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions collector/fixtures/sys.ttar
Original file line number Diff line number Diff line change
Expand Up @@ -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 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -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 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
44 changes: 41 additions & 3 deletions collector/thermal_zone_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}

Expand All @@ -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
}
85 changes: 85 additions & 0 deletions vendor/github.com/prometheus/procfs/arp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 131 additions & 0 deletions vendor/github.com/prometheus/procfs/crypto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 664025d

Please sign in to comment.