Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add device prometheus label #4

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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