Skip to content

Commit

Permalink
feat: add device prometheus label
Browse files Browse the repository at this point in the history
This commit ensures that the Unix deveice is added as a prometheus
label.
  • Loading branch information
rickstaa committed Nov 8, 2023
1 parent 516f4f1 commit d4e76f8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions liquidctl-exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type status struct {
}

// Metrics store per device ({deviceID: {metricID: prom.Gauge}})
var devices = map[string]map[string]prometheus.Gauge{}
var devices = map[string]map[string]*prometheus.GaugeVec{}

// path to liquidctl executable
var path string
Expand All @@ -63,19 +63,20 @@ func init() {
// Register metrics available for each liquidctl device
for _, d := range liquidctl_stats() {
dname := deviceName(d.Address)
devices[dname] = map[string]prometheus.Gauge{}
devices[dname] = map[string]*prometheus.GaugeVec{}
for _, m := range d.Status {
name := metricName(m.Key, dname)

// Register metrics based on type.
switch t := m.Value.(type) {
case float64:
log.Infof("Registering metric '%s' for '%s' device", name, dname)
devices[dname][name] = prometheus.NewGauge(
devices[dname][name] = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: name,
Help: fmt.Sprintf("%s %s (%s).", d.Description, m.Key, m.Unit),
},
[]string{"device"},
)
prometheus.MustRegister(devices[dname][name])
default: // Currently only float64 are implemented
Expand Down Expand Up @@ -122,7 +123,7 @@ func main() {
// Push metric to db if it was registered
_, ok := devices[dname][name]
if ok {
devices[dname][name].Set(m.Value.(float64))
devices[dname][name].WithLabelValues(dname).Set(m.Value.(float64))
}
}
}
Expand Down

0 comments on commit d4e76f8

Please sign in to comment.