/
metrics.go
78 lines (67 loc) · 2.74 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
package ethereum
import "github.com/prometheus/client_golang/prometheus"
type Metrics struct {
beacon string
// The number of blocks that have been fetched.
blocksFetched *prometheus.CounterVec
// The number of blocks fetches that have failed.
blocksFetchErrors *prometheus.CounterVec
// BlockCacheHit is the number of times a block was found in the cache.
blockCacheHit *prometheus.CounterVec
// BlockCacheMiss is the number of times a block was not found in the cache.
blockCacheMiss *prometheus.CounterVec
// PreloadBlockQueueSize is the number of blocks in the preload queue.
preloadBlockQueueSize *prometheus.GaugeVec
}
func NewMetrics(namespace, beaconNodeName string) *Metrics {
namespace += "_ethereum"
m := &Metrics{
beacon: beaconNodeName,
blocksFetched: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Name: "blocks_fetched_total",
Help: "The number of blocks that have been fetched",
}, []string{"network", "beacon"}),
blocksFetchErrors: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Name: "blocks_fetch_errors_total",
Help: "The number of blocks that have failed to be fetched",
}, []string{"network", "beacon"}),
blockCacheHit: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Name: "block_cache_hit_total",
Help: "The number of times a block was found in the cache",
}, []string{"network", "beacon"}),
blockCacheMiss: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Name: "block_cache_miss_total",
Help: "The number of times a block was not found in the cache",
}, []string{"network", "beacon"}),
preloadBlockQueueSize: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Name: "preload_block_queue_size",
Help: "The number of blocks in the preload queue",
}, []string{"network", "beacon"}),
}
prometheus.MustRegister(m.blocksFetched)
prometheus.MustRegister(m.blocksFetchErrors)
prometheus.MustRegister(m.blockCacheHit)
prometheus.MustRegister(m.blockCacheMiss)
prometheus.MustRegister(m.preloadBlockQueueSize)
return m
}
func (m *Metrics) IncBlocksFetched(network string) {
m.blocksFetched.WithLabelValues(network, m.beacon).Inc()
}
func (m *Metrics) IncBlocksFetchErrors(network string) {
m.blocksFetchErrors.WithLabelValues(network, m.beacon).Inc()
}
func (m *Metrics) IncBlockCacheHit(network string) {
m.blockCacheHit.WithLabelValues(network, m.beacon).Inc()
}
func (m *Metrics) IncBlockCacheMiss(network string) {
m.blockCacheMiss.WithLabelValues(network, m.beacon).Inc()
}
func (m *Metrics) SetPreloadBlockQueueSize(network string, size int) {
m.preloadBlockQueueSize.WithLabelValues(network, m.beacon).Set(float64(size))
}