-
Notifications
You must be signed in to change notification settings - Fork 1
/
collector.go
56 lines (48 loc) · 1.1 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
package main
import (
"github.com/prometheus/client_golang/prometheus"
)
type OnionStatus struct {
Up float64
Host string
Type string
Latency float64
}
var statuses map[string]OnionStatus
type OnionCollector struct {
Up *prometheus.Desc
Latency *prometheus.Desc
}
func NewOnionCollector() *OnionCollector {
statuses = make(map[string]OnionStatus)
return &OnionCollector{
Up: prometheus.NewDesc("onion_service_up", "", []string{"name", "address", "type"}, nil),
Latency: prometheus.NewDesc("onion_service_latency", "", []string{"name", "address", "type"}, nil),
}
}
func (oc *OnionCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- oc.Up
ch <- oc.Latency
}
func (oc *OnionCollector) Collect(ch chan<- prometheus.Metric) {
for name, status := range statuses {
ch <- prometheus.MustNewConstMetric(
oc.Up,
prometheus.GaugeValue,
status.Up,
name,
status.Host,
status.Type,
)
if status.Up != 0 {
ch <- prometheus.MustNewConstMetric(
oc.Latency,
prometheus.GaugeValue,
status.Latency,
name,
status.Host,
status.Type,
)
}
}
}