-
Notifications
You must be signed in to change notification settings - Fork 84
/
metrics.go
77 lines (66 loc) · 2.09 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
package instance
import (
"encoding/hex"
"log"
"time"
specqbft "github.com/bloxapp/ssv-spec/qbft"
spectypes "github.com/bloxapp/ssv-spec/types"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
metricsStageDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "ssv_validator_instance_stage_duration_seconds",
Help: "Instance stage duration (seconds)",
Buckets: []float64{0.02, 0.05, 0.1, 0.2, 0.5, 1, 1.5, 2, 5},
}, []string{"stage", "pubKey"})
metricsRound = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "ssv_qbft_instance_round",
Help: "QBFT instance round",
}, []string{"roleType", "pubKey"})
)
func init() {
allMetrics := []prometheus.Collector{
metricsStageDuration,
metricsRound,
}
for _, c := range allMetrics {
if err := prometheus.Register(c); err != nil {
log.Println("could not register prometheus collector")
}
}
}
type metrics struct {
StageStart time.Time
proposalDuration prometheus.Observer
prepareDuration prometheus.Observer
commitDuration prometheus.Observer
round prometheus.Gauge
}
func newMetrics(msgID spectypes.MessageID) *metrics {
hexPubKey := hex.EncodeToString(msgID.GetPubKey())
return &metrics{
proposalDuration: metricsStageDuration.WithLabelValues("proposal", hexPubKey),
prepareDuration: metricsStageDuration.WithLabelValues("prepare", hexPubKey),
commitDuration: metricsStageDuration.WithLabelValues("commit", hexPubKey),
round: metricsRound.WithLabelValues("validator", hexPubKey),
}
}
func (m *metrics) StartStage() {
m.StageStart = time.Now()
}
func (m *metrics) EndStageProposal() {
m.proposalDuration.Observe(time.Since(m.StageStart).Seconds())
m.StageStart = time.Now()
}
func (m *metrics) EndStagePrepare() {
m.prepareDuration.Observe(time.Since(m.StageStart).Seconds())
m.StageStart = time.Now()
}
func (m *metrics) EndStageCommit() {
m.commitDuration.Observe(time.Since(m.StageStart).Seconds())
m.StageStart = time.Now()
}
func (m *metrics) SetRound(round specqbft.Round) {
m.round.Set(float64(round))
}