-
Notifications
You must be signed in to change notification settings - Fork 0
/
collector.go
96 lines (82 loc) · 1.73 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
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"math"
"github.com/loa/temovex-exporter/temovex"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
type collector struct {
Temovex *temovex.Client
tempMetric *prometheus.Desc
}
func newCollector(address string) *collector {
col := collector{
tempMetric: prometheus.NewDesc(
"temovex_temperature_c",
"Temperature in celcius",
[]string{"name"},
nil,
),
}
var err error
col.Temovex, err = temovex.NewClient(address)
if err != nil {
log.Fatal(err.Error())
}
return &col
}
func (col *collector) Describe(ch chan<- *prometheus.Desc) {
ch <- col.tempMetric
}
func (col *collector) Collect(ch chan<- prometheus.Metric) {
if val, err := col.Temovex.GetSet(); err != nil {
log.Fatal(err.Error())
} else {
ch <- prometheus.MustNewConstMetric(
col.tempMetric,
prometheus.GaugeValue,
math.Round(val*10)/10,
"set",
)
}
if val, err := col.Temovex.GetAL(); err != nil {
log.Fatal(err.Error())
} else {
ch <- prometheus.MustNewConstMetric(
col.tempMetric,
prometheus.GaugeValue,
math.Round(val*10)/10,
"al",
)
}
if val, err := col.Temovex.GetFL(); err != nil {
log.Fatal(err.Error())
} else {
ch <- prometheus.MustNewConstMetric(
col.tempMetric,
prometheus.GaugeValue,
math.Round(val*10)/10,
"fl",
)
}
if val, err := col.Temovex.GetUL(); err != nil {
log.Fatal(err.Error())
} else {
ch <- prometheus.MustNewConstMetric(
col.tempMetric,
prometheus.GaugeValue,
math.Round(val*10)/10,
"ul",
)
}
if val, err := col.Temovex.GetTL(); err != nil {
log.Fatal(err.Error())
} else {
ch <- prometheus.MustNewConstMetric(
col.tempMetric,
prometheus.GaugeValue,
math.Round(val*10)/10,
"tl",
)
}
}