-
Notifications
You must be signed in to change notification settings - Fork 884
/
stats.go
58 lines (48 loc) · 1.36 KB
/
stats.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
// SPDX-License-Identifier:Apache-2.0
package layer2
import "github.com/prometheus/client_golang/prometheus"
var stats = metrics{
in: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "metallb",
Subsystem: "layer2",
Name: "requests_received",
Help: "Number of layer2 requests received for owned IPs",
}, []string{
"ip",
}),
out: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "metallb",
Subsystem: "layer2",
Name: "responses_sent",
Help: "Number of layer2 responses sent for owned IPs in response to requests",
}, []string{
"ip",
}),
gratuitous: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "metallb",
Subsystem: "layer2",
Name: "gratuitous_sent",
Help: "Number of gratuitous layer2 packets sent for owned IPs as a result of failovers",
}, []string{
"ip",
}),
}
type metrics struct {
in *prometheus.CounterVec
out *prometheus.CounterVec
gratuitous *prometheus.CounterVec
}
func init() {
prometheus.MustRegister(stats.in)
prometheus.MustRegister(stats.out)
prometheus.MustRegister(stats.gratuitous)
}
func (m *metrics) GotRequest(addr string) {
m.in.WithLabelValues(addr).Add(1)
}
func (m *metrics) SentResponse(addr string) {
m.out.WithLabelValues(addr).Add(1)
}
func (m *metrics) SentGratuitous(addr string) {
m.gratuitous.WithLabelValues(addr).Add(1)
}