-
Notifications
You must be signed in to change notification settings - Fork 147
/
chain_consensus.go
51 lines (38 loc) · 1.34 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
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/iotaledger/wasp/packages/isc"
)
type IChainConsensusMetrics interface {
SetVMRunTime(time.Duration)
IncVMRunsCounter()
}
var (
_ IChainConsensusMetrics = &emptyChainConsensusMetric{}
_ IChainConsensusMetrics = &chainConsensusMetric{}
)
type emptyChainConsensusMetric struct{}
func NewEmptyChainConsensusMetric() IChainConsensusMetrics { return &emptyChainConsensusMetric{} }
func (m *emptyChainConsensusMetric) SetVMRunTime(duration time.Duration) {}
func (m *emptyChainConsensusMetric) IncVMRunsCounter() {}
type chainConsensusMetric struct {
provider *ChainMetricsProvider
metricsLabels prometheus.Labels
}
func newChainConsensusMetric(provider *ChainMetricsProvider, chainID isc.ChainID) *chainConsensusMetric {
metricsLabels := getChainLabels(chainID)
// init values so they appear in prometheus
provider.vmRunTime.With(metricsLabels)
provider.vmRunsTotal.With(metricsLabels)
return &chainConsensusMetric{
provider: provider,
metricsLabels: metricsLabels,
}
}
func (m *chainConsensusMetric) SetVMRunTime(duration time.Duration) {
m.provider.vmRunTime.With(m.metricsLabels).Set(duration.Seconds())
}
func (m *chainConsensusMetric) IncVMRunsCounter() {
m.provider.vmRunsTotal.With(m.metricsLabels).Inc()
}