-
Notifications
You must be signed in to change notification settings - Fork 0
/
prom-exporter.go
36 lines (29 loc) · 934 Bytes
/
prom-exporter.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
package main
import "github.com/prometheus/client_golang/prometheus"
var (
priceDesc = prometheus.NewDesc(
prometheus.BuildFQName("fuelwatch", "", "price_euros"),
"The price for the different types of fuel",
[]string{"stationID", "fuel_name"},
nil,
)
updateTimeDesc = prometheus.NewDesc(
prometheus.BuildFQName("fuelwatch", "", "update_timestamp"),
"The UNIX timestamp when the prices were last updated",
[]string{"stationID"},
nil,
)
)
type fuelCollector struct{}
func (fuelCollector) Describe(desc chan<- *prometheus.Desc) {
desc <- priceDesc
desc <- updateTimeDesc
}
func (fuelCollector) Collect(ch chan<- prometheus.Metric) {
fi := readFuelInfo()
for name, p := range fi.prices {
ch <- prometheus.MustNewConstMetric(priceDesc, prometheus.GaugeValue, p, fi.station, name)
}
ch <- prometheus.MustNewConstMetric(updateTimeDesc, prometheus.GaugeValue, float64(fi.lastUpdate.Unix()),
fi.station)
}