Scrape cooling_device state

Signed-off-by: Alex Schmitz <alex.schmitz@gmail.com>
This commit is contained in:
Alex Schmitz 2019-08-11 22:52:16 -05:00 committed by Alex Schmitz
commit 664025d60c
No known key found for this signature in database
GPG key ID: DB2FA6E56B5D4228
11 changed files with 557 additions and 3 deletions

View file

@ -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
}