-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
57 lines (52 loc) · 1.54 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
package quorum
import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
)
type Metrics struct {
splitBrain prometheus.Gauge
raftMembers prometheus.Gauge
memberlistMembers prometheus.Gauge
}
// NewMetrics returns a populated, and registered *Metrics, or an error.
func NewMetrics() (*Metrics, error) {
a := &Metrics{
splitBrain: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "quorum",
Name: "split_brain",
Help: "whether this node is in split brain mode or not",
}),
raftMembers: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "quorum",
Name: "raft_members",
Help: "how many nodes are in the raft group",
}),
memberlistMembers: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "quorum",
Name: "memberlist_members",
Help: "how many nodes are in the memberlist group",
}),
}
return a, a.Register()
}
func (a *Metrics) SplitBrain(val int) {
a.splitBrain.Set(float64(val))
}
func (a *Metrics) RaftMembers(val int64) {
a.raftMembers.Set(float64(val))
}
func (a *Metrics) MemberlistMembers(val int64) {
a.memberlistMembers.Set(float64(val))
}
func (a *Metrics) Register() error {
if err := prometheus.Register(a.splitBrain); err != nil {
return errors.Wrap(err, "registering splitBrain")
}
if err := prometheus.Register(a.raftMembers); err != nil {
return errors.Wrap(err, "registering splitBrain")
}
if err := prometheus.Register(a.memberlistMembers); err != nil {
return errors.Wrap(err, "registering splitBrain")
}
return nil
}