-
Notifications
You must be signed in to change notification settings - Fork 147
/
chain_node_conn.go
95 lines (82 loc) · 3.18 KB
/
chain_node_conn.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
88
89
90
91
92
93
94
95
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/iotaledger/wasp/packages/isc"
)
type ChainNodeConnMetricsProvider struct {
l1RequestReceived *prometheus.CounterVec
l1AliasOutputReceived *prometheus.CounterVec
txPublishStarted *prometheus.CounterVec
txPublishResult *prometheus.HistogramVec
}
func newChainNodeConnMetricsProvider() *ChainNodeConnMetricsProvider {
return &ChainNodeConnMetricsProvider{
l1RequestReceived: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "iota_wasp",
Subsystem: "node_conn",
Name: "l1_request_received",
Help: "A number of confirmed requests received from L1.",
}, []string{labelNameChain}),
l1AliasOutputReceived: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "iota_wasp",
Subsystem: "node_conn",
Name: "l1_alias_output_received",
Help: "A number of confirmed alias outputs received from L1.",
}, []string{labelNameChain}),
txPublishStarted: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "iota_wasp",
Subsystem: "node_conn",
Name: "tx_publish_started",
Help: "A number of transactions submitted for publication in L1.",
}, []string{labelNameChain}),
txPublishResult: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "node_conn",
Name: "tx_publish_result",
Help: "The duration (s) to publish a transaction.",
Buckets: postTimeBuckets,
}, []string{labelNameChain, labelTxPublishResult}),
}
}
func (p *ChainNodeConnMetricsProvider) register(reg prometheus.Registerer) {
reg.MustRegister(
p.l1RequestReceived,
p.l1AliasOutputReceived,
p.txPublishStarted,
p.txPublishResult,
)
}
func (p *ChainNodeConnMetricsProvider) createForChain(chainID isc.ChainID) *ChainNodeConnMetrics {
return newChainNodeConnMetrics(p, chainID)
}
type ChainNodeConnMetrics struct {
ncL1RequestReceived prometheus.Counter
ncL1AliasOutputReceived prometheus.Counter
ncTXPublishStarted prometheus.Counter
ncTXPublishResult map[bool]prometheus.Observer
}
func newChainNodeConnMetrics(collectors *ChainNodeConnMetricsProvider, chainID isc.ChainID) *ChainNodeConnMetrics {
labels := getChainLabels(chainID)
return &ChainNodeConnMetrics{
ncL1RequestReceived: collectors.l1RequestReceived.With(labels),
ncL1AliasOutputReceived: collectors.l1AliasOutputReceived.With(labels),
ncTXPublishStarted: collectors.txPublishStarted.With(labels),
ncTXPublishResult: map[bool]prometheus.Observer{
true: collectors.txPublishResult.MustCurryWith(labels).With(prometheus.Labels{labelTxPublishResult: "confirmed"}),
false: collectors.txPublishResult.MustCurryWith(labels).With(prometheus.Labels{labelTxPublishResult: "rejected"}),
},
}
}
func (m *ChainNodeConnMetrics) L1RequestReceived() {
m.ncL1RequestReceived.Inc()
}
func (m *ChainNodeConnMetrics) L1AliasOutputReceived() {
m.ncL1AliasOutputReceived.Inc()
}
func (m *ChainNodeConnMetrics) TXPublishStarted() {
m.ncTXPublishStarted.Inc()
}
func (m *ChainNodeConnMetrics) TXPublishResult(confirmed bool, duration time.Duration) {
m.ncTXPublishResult[confirmed].Observe(duration.Seconds())
}