-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
79 lines (65 loc) · 2.42 KB
/
metrics.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
package main
import (
"fmt"
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
// Metrics contains all logic for prometheus metrics
type Metrics struct {
ErrorsTotal prometheus.Counter
LBTotal prometheus.Counter
LBHealthy prometheus.Gauge
LBHealthyEndpoints *prometheus.GaugeVec
}
// Init initializes the metrics
func (m *Metrics) Init() error {
// -- ErrorsTotal ----------------------------------------------------------
m.ErrorsTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Subsystem: "general",
Name: "errors_total",
Help: "Total number of errors happened.",
})
err := prometheus.Register(m.ErrorsTotal)
if err != nil {
return fmt.Errorf("couldn't register ErrorsTotal counter, see: %v", err)
}
// -- LBTotal --------------------------------------------------------------
m.LBTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Subsystem: "general",
Name: "lb_total",
Help: "Amount of total configured loadbalancers",
})
err = prometheus.Register(m.LBTotal)
if err != nil {
return fmt.Errorf("couldn't register LBTotal counter, see: %v", err)
}
// -- LBHealthy ------------------------------------------------------------
m.LBHealthy = prometheus.NewGauge(
prometheus.GaugeOpts{
Subsystem: "general",
Name: "lb_healthy",
Help: "Amount of healthy loadbalancers",
})
err = prometheus.Register(m.LBHealthy)
if err != nil {
return fmt.Errorf("couldn't register LBHealthy counter, see: %v", err)
}
// -- LBHealthyEndpoints ---------------------------------------------------
m.LBHealthyEndpoints = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Subsystem: "general",
Name: "lb_healthy_endpoints",
Help: "Loadbalancers with amount of healthy endpoints",
},
[]string{"lb"})
err = prometheus.Register(m.LBHealthyEndpoints)
if err != nil {
return fmt.Errorf("couldn't register LBHealthyEndpoints gauge, see: %v", err)
}
// -------------------------------------------------------------------------
http.Handle("/metrics", promhttp.Handler())
return nil
}