-
Notifications
You must be signed in to change notification settings - Fork 147
/
chain_consensus.go
80 lines (68 loc) · 2.33 KB
/
chain_consensus.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
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/iotaledger/wasp/packages/isc"
)
type ChainConsensusMetricsProvider struct {
vmRunTime *prometheus.HistogramVec
vmRunTimePerReq *prometheus.HistogramVec
vmRunReqCount *prometheus.HistogramVec
}
func newChainConsensusMetricsProvider() *ChainConsensusMetricsProvider {
return &ChainConsensusMetricsProvider{
vmRunTime: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "consensus",
Name: "vm_run_time",
Help: "Time (s) it takes to run the VM per chain block.",
Buckets: execTimeBuckets,
}, []string{labelNameChain}),
vmRunTimePerReq: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "consensus",
Name: "vm_run_time_per_req",
Help: "Time (s) it takes to run the VM per request.",
Buckets: execTimeBuckets,
}, []string{labelNameChain}),
vmRunReqCount: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "consensus",
Name: "vm_run_req_count",
Help: "Number of requests processed per VM run.",
Buckets: recCountBuckets,
}, []string{labelNameChain}),
}
}
func (p *ChainConsensusMetricsProvider) register(reg prometheus.Registerer) {
reg.MustRegister(
p.vmRunTime,
p.vmRunTimePerReq,
p.vmRunReqCount,
)
}
func (p *ChainConsensusMetricsProvider) createForChain(chainID isc.ChainID) *ChainConsensusMetrics {
return newChainConsensusMetrics(p, chainID)
}
type ChainConsensusMetrics struct {
labels prometheus.Labels
collectors *ChainConsensusMetricsProvider
}
func newChainConsensusMetrics(collectors *ChainConsensusMetricsProvider, chainID isc.ChainID) *ChainConsensusMetrics {
labels := getChainLabels(chainID)
// init values so they appear in prometheus
collectors.vmRunTime.With(labels)
collectors.vmRunTimePerReq.With(labels)
collectors.vmRunReqCount.With(labels)
return &ChainConsensusMetrics{
collectors: collectors,
labels: labels,
}
}
func (m *ChainConsensusMetrics) VMRun(duration time.Duration, reqCount int) {
d := duration.Seconds()
r := float64(reqCount)
m.collectors.vmRunTime.With(m.labels).Observe(d)
m.collectors.vmRunTimePerReq.With(m.labels).Observe(d / r)
m.collectors.vmRunReqCount.With(m.labels).Observe(r)
}