/
metrics.go
68 lines (60 loc) · 1.95 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
package consensus
import (
"github.com/go-kit/kit/metrics"
"github.com/go-kit/kit/metrics/discard"
prometheus "github.com/go-kit/kit/metrics/prometheus"
stdprometheus "github.com/prometheus/client_golang/prometheus"
)
// Metrics represents the consensus metrics
type Metrics struct {
// No.of validators
Validators metrics.Gauge
// No.of rounds
Rounds metrics.Gauge
// No.of transactions in the block
NumTxs metrics.Gauge
//Time between current block and the previous block in seconds
BlockInterval metrics.Gauge
}
// GetPrometheusMetrics return the consensus metrics instance
func GetPrometheusMetrics(namespace string, labelsWithValues ...string) *Metrics {
labels := []string{}
for i := 0; i < len(labelsWithValues); i += 2 {
labels = append(labels, labelsWithValues[i])
}
return &Metrics{
Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "consensus",
Name: "validators",
Help: "Number of validators.",
}, labels).With(labelsWithValues...),
Rounds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "consensus",
Name: "rounds",
Help: "Number of rounds.",
}, labels).With(labelsWithValues...),
NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "consensus",
Name: "num_txs",
Help: "Number of transactions.",
}, labels).With(labelsWithValues...),
BlockInterval: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "consensus",
Name: "block_interval",
Help: "Time between current block and the previous block in seconds.",
}, labels).With(labelsWithValues...),
}
}
// NilMetrics will return the non operational metrics
func NilMetrics() *Metrics {
return &Metrics{
Validators: discard.NewGauge(),
Rounds: discard.NewGauge(),
NumTxs: discard.NewGauge(),
BlockInterval: discard.NewGauge(),
}
}