-
Notifications
You must be signed in to change notification settings - Fork 147
/
chain_snapshots.go
74 lines (62 loc) · 2.13 KB
/
chain_snapshots.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
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/iotaledger/wasp/packages/isc"
)
type ChainSnapshotsMetricsProvider struct {
created *countAndMaxMetrics
createDuration *prometheus.HistogramVec
}
func newChainSnapshotsMetricsProvider() *ChainSnapshotsMetricsProvider {
return &ChainSnapshotsMetricsProvider{
created: newCountAndMaxMetrics(
prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "iota_wasp",
Subsystem: "snapshots",
Name: "created",
Help: "Total number of snapshots created",
}, []string{labelNameChain}),
prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "iota_wasp",
Subsystem: "snapshots",
Name: "max_index",
Help: "Largest index of created snapshot",
}, []string{labelNameChain}),
),
createDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "snapshots",
Name: "create_duration",
Help: "The duration (s) of creating snapshot and storing it in file system",
Buckets: execTimeBuckets,
}, []string{labelNameChain}),
}
}
func (p *ChainSnapshotsMetricsProvider) register(reg prometheus.Registerer) {
reg.MustRegister(
p.createDuration,
)
reg.MustRegister(p.created.collectors()...)
}
func (p *ChainSnapshotsMetricsProvider) createForChain(chainID isc.ChainID) *ChainSnapshotsMetrics {
return newChainSnapshotsMetrics(p, chainID)
}
type ChainSnapshotsMetrics struct {
labels prometheus.Labels
collectors *ChainSnapshotsMetricsProvider
}
func newChainSnapshotsMetrics(collectors *ChainSnapshotsMetricsProvider, chainID isc.ChainID) *ChainSnapshotsMetrics {
labels := getChainLabels(chainID)
// init values so they appear in prometheus
collectors.created.with(labels)
collectors.createDuration.With(labels)
return &ChainSnapshotsMetrics{
collectors: collectors,
labels: labels,
}
}
func (m *ChainSnapshotsMetrics) SnapshotCreated(duration time.Duration, stateIndex uint32) {
m.collectors.createDuration.With(m.labels).Observe(duration.Seconds())
m.collectors.created.countValue(m.labels, float64(stateIndex))
}