-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollector.go
83 lines (77 loc) · 2.68 KB
/
collector.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import "github.com/prometheus/client_golang/prometheus"
type Collector struct {
batteryPercentage *prometheus.Desc
batteryVoltage *prometheus.Desc
charging *prometheus.Desc
uptime *prometheus.Desc
distanceDriven *prometheus.Desc
cleaningTime *prometheus.Desc
totalRuns *prometheus.Desc
}
func newCollector() *Collector {
return &Collector{
batteryPercentage: prometheus.NewDesc("rowenta_battery_level",
"Battery Percentage",
nil, nil,
),
batteryVoltage: prometheus.NewDesc("rowenta_battery_voltage_volts",
"Battery Voltage in volts",
nil, nil,
),
charging: prometheus.NewDesc("rowenta_charging",
"Charging state",
nil, nil,
),
uptime: prometheus.NewDesc("rowenta_uptime_seconds",
"Robot uptime in seconds",
nil, nil,
),
distanceDriven: prometheus.NewDesc("rowenta_distance_driven_meters",
"Distance travelled in meters",
nil, nil,
),
cleaningTime: prometheus.NewDesc("rowenta_clean_time_seconds",
"Time spent cleaning time in seconds",
nil, nil,
),
totalRuns: prometheus.NewDesc("rowenta_runs_total",
"Total number of runs",
nil, nil,
),
}
}
func (collector *Collector) Describe(ch chan<- *prometheus.Desc) {
ch <- collector.batteryPercentage
ch <- collector.batteryVoltage
ch <- collector.charging
ch <- collector.uptime
ch <- collector.distanceDriven
ch <- collector.cleaningTime
ch <- collector.totalRuns
}
func (collector *Collector) Collect(ch chan<- prometheus.Metric) {
status, err := GetStatus()
if err != nil {
ch <- prometheus.NewInvalidMetric(
prometheus.NewDesc("rowenta_status_error",
"Error getting rowenta status", nil, nil),
err)
} else {
ch <- prometheus.MustNewConstMetric(collector.batteryPercentage, prometheus.GaugeValue, status.BatteryPercentage)
ch <- prometheus.MustNewConstMetric(collector.batteryVoltage, prometheus.GaugeValue, status.BatteryVoltageVolts)
ch <- prometheus.MustNewConstMetric(collector.charging, prometheus.GaugeValue, status.Charging)
ch <- prometheus.MustNewConstMetric(collector.uptime, prometheus.GaugeValue, status.UptimeSeconds)
}
statistics, err := GetPermanentStatistics()
if err != nil {
ch <- prometheus.NewInvalidMetric(
prometheus.NewDesc("rowenta_statistics_error",
"Error getting rowenta statistics", nil, nil),
err)
} else {
ch <- prometheus.MustNewConstMetric(collector.distanceDriven, prometheus.CounterValue, statistics.TotalDistanceDrivenMeters)
ch <- prometheus.MustNewConstMetric(collector.cleaningTime, prometheus.CounterValue, statistics.TotalCleaningTimeSeconds)
ch <- prometheus.MustNewConstMetric(collector.totalRuns, prometheus.CounterValue, statistics.TotalNumberOfCleaningRuns)
}
}