-
Notifications
You must be signed in to change notification settings - Fork 147
/
chain_blockwal.go
87 lines (74 loc) · 2.48 KB
/
chain_blockwal.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
79
80
81
82
83
84
85
86
87
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/iotaledger/wasp/packages/isc"
)
type ChainBlockWALMetricsProvider struct {
failedWrites *prometheus.CounterVec
failedReads *prometheus.CounterVec
blocksAdded *countAndMaxMetrics
}
func newChainBlockWALMetricsProvider() *ChainBlockWALMetricsProvider {
return &ChainBlockWALMetricsProvider{
failedWrites: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "iota_wasp",
Subsystem: "wal",
Name: "failed_writes_total",
Help: "Total number of writes to WAL that failed",
}, []string{labelNameChain}),
failedReads: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "iota_wasp",
Subsystem: "wal",
Name: "failed_reads_total",
Help: "Total number of reads failed while replaying WAL",
}, []string{labelNameChain}),
blocksAdded: newCountAndMaxMetrics(
prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "iota_wasp",
Subsystem: "wal",
Name: "blocks_added",
Help: "Total number of blocks added into WAL",
}, []string{labelNameChain}),
prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "iota_wasp",
Subsystem: "wal",
Name: "max_block_index",
Help: "Largest index of block added into WAL",
}, []string{labelNameChain}),
),
}
}
func (p *ChainBlockWALMetricsProvider) register(reg prometheus.Registerer) {
reg.MustRegister(
p.failedReads,
p.failedWrites,
)
reg.MustRegister(p.blocksAdded.collectors()...)
}
func (p *ChainBlockWALMetricsProvider) createForChain(chainID isc.ChainID) *ChainBlockWALMetrics {
return newChainBlockWALMetrics(p, chainID)
}
type ChainBlockWALMetrics struct {
labels prometheus.Labels
collectors *ChainBlockWALMetricsProvider
}
func newChainBlockWALMetrics(collectors *ChainBlockWALMetricsProvider, chainID isc.ChainID) *ChainBlockWALMetrics {
labels := getChainLabels(chainID)
// init values so they appear in prometheus
collectors.failedWrites.With(labels)
collectors.failedReads.With(labels)
collectors.blocksAdded.with(labels)
return &ChainBlockWALMetrics{
collectors: collectors,
labels: labels,
}
}
func (m *ChainBlockWALMetrics) IncFailedWrites() {
m.collectors.failedWrites.With(m.labels).Inc()
}
func (m *ChainBlockWALMetrics) IncFailedReads() {
m.collectors.failedReads.With(m.labels).Inc()
}
func (m *ChainBlockWALMetrics) BlockWritten(blockIndex uint32) {
m.collectors.blocksAdded.countValue(m.labels, float64(blockIndex))
}