-
Notifications
You must be signed in to change notification settings - Fork 1
/
prometheus.go
45 lines (42 loc) · 1.07 KB
/
prometheus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"math"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/prometheus/pkg/value"
)
func CreateGauges(s *Sensor) {
promauto.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "sensor",
Subsystem: "govee",
Name: "temperature",
ConstLabels: prometheus.Labels{"name": s.Name},
}, func() float64 {
if s.IsStale() {
return math.Float64frombits(value.StaleNaN)
}
return s.Temperature()
})
promauto.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "sensor",
Subsystem: "govee",
Name: "humidity",
ConstLabels: prometheus.Labels{"name": s.Name},
}, func() float64 {
if s.IsStale() {
return math.Float64frombits(value.StaleNaN)
}
return s.Humidity()
})
promauto.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "sensor",
Subsystem: "govee",
Name: "battery_level",
ConstLabels: prometheus.Labels{"name": s.Name},
}, func() float64 {
if s.IsStale() {
return math.Float64frombits(value.StaleNaN)
}
return s.Battery()
})
}