-
Notifications
You must be signed in to change notification settings - Fork 671
/
tx_metrics.go
148 lines (125 loc) · 4.39 KB
/
tx_metrics.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package metrics
import (
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/ava-labs/avalanchego/utils/wrappers"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
)
var _ txs.Visitor = (*txMetrics)(nil)
type txMetrics struct {
numAddDelegatorTxs,
numAddSubnetValidatorTxs,
numAddValidatorTxs,
numAdvanceTimeTxs,
numCreateChainTxs,
numCreateSubnetTxs,
numExportTxs,
numImportTxs,
numRewardValidatorTxs,
numRemoveSubnetValidatorTxs,
numTransformSubnetTxs,
numAddPermissionlessValidatorTxs,
numAddPermissionlessDelegatorTxs,
numTransferSubnetOwnershipTxs,
numBaseTxs prometheus.Counter
}
func newTxMetrics(
namespace string,
registerer prometheus.Registerer,
) (*txMetrics, error) {
errs := wrappers.Errs{}
m := &txMetrics{
numAddDelegatorTxs: newTxMetric(namespace, "add_delegator", registerer, &errs),
numAddSubnetValidatorTxs: newTxMetric(namespace, "add_subnet_validator", registerer, &errs),
numAddValidatorTxs: newTxMetric(namespace, "add_validator", registerer, &errs),
numAdvanceTimeTxs: newTxMetric(namespace, "advance_time", registerer, &errs),
numCreateChainTxs: newTxMetric(namespace, "create_chain", registerer, &errs),
numCreateSubnetTxs: newTxMetric(namespace, "create_subnet", registerer, &errs),
numExportTxs: newTxMetric(namespace, "export", registerer, &errs),
numImportTxs: newTxMetric(namespace, "import", registerer, &errs),
numRewardValidatorTxs: newTxMetric(namespace, "reward_validator", registerer, &errs),
numRemoveSubnetValidatorTxs: newTxMetric(namespace, "remove_subnet_validator", registerer, &errs),
numTransformSubnetTxs: newTxMetric(namespace, "transform_subnet", registerer, &errs),
numAddPermissionlessValidatorTxs: newTxMetric(namespace, "add_permissionless_validator", registerer, &errs),
numAddPermissionlessDelegatorTxs: newTxMetric(namespace, "add_permissionless_delegator", registerer, &errs),
numTransferSubnetOwnershipTxs: newTxMetric(namespace, "transfer_subnet_ownership", registerer, &errs),
numBaseTxs: newTxMetric(namespace, "base", registerer, &errs),
}
return m, errs.Err
}
func newTxMetric(
namespace string,
txName string,
registerer prometheus.Registerer,
errs *wrappers.Errs,
) prometheus.Counter {
txMetric := prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: txName + "_txs_accepted",
Help: fmt.Sprintf("Number of %s transactions accepted", txName),
})
errs.Add(registerer.Register(txMetric))
return txMetric
}
func (m *txMetrics) AddValidatorTx(*txs.AddValidatorTx) error {
m.numAddValidatorTxs.Inc()
return nil
}
func (m *txMetrics) AddSubnetValidatorTx(*txs.AddSubnetValidatorTx) error {
m.numAddSubnetValidatorTxs.Inc()
return nil
}
func (m *txMetrics) AddDelegatorTx(*txs.AddDelegatorTx) error {
m.numAddDelegatorTxs.Inc()
return nil
}
func (m *txMetrics) CreateChainTx(*txs.CreateChainTx) error {
m.numCreateChainTxs.Inc()
return nil
}
func (m *txMetrics) CreateSubnetTx(*txs.CreateSubnetTx) error {
m.numCreateSubnetTxs.Inc()
return nil
}
func (m *txMetrics) ImportTx(*txs.ImportTx) error {
m.numImportTxs.Inc()
return nil
}
func (m *txMetrics) ExportTx(*txs.ExportTx) error {
m.numExportTxs.Inc()
return nil
}
func (m *txMetrics) AdvanceTimeTx(*txs.AdvanceTimeTx) error {
m.numAdvanceTimeTxs.Inc()
return nil
}
func (m *txMetrics) RewardValidatorTx(*txs.RewardValidatorTx) error {
m.numRewardValidatorTxs.Inc()
return nil
}
func (m *txMetrics) RemoveSubnetValidatorTx(*txs.RemoveSubnetValidatorTx) error {
m.numRemoveSubnetValidatorTxs.Inc()
return nil
}
func (m *txMetrics) TransformSubnetTx(*txs.TransformSubnetTx) error {
m.numTransformSubnetTxs.Inc()
return nil
}
func (m *txMetrics) AddPermissionlessValidatorTx(*txs.AddPermissionlessValidatorTx) error {
m.numAddPermissionlessValidatorTxs.Inc()
return nil
}
func (m *txMetrics) AddPermissionlessDelegatorTx(*txs.AddPermissionlessDelegatorTx) error {
m.numAddPermissionlessDelegatorTxs.Inc()
return nil
}
func (m *txMetrics) TransferSubnetOwnershipTx(*txs.TransferSubnetOwnershipTx) error {
m.numTransferSubnetOwnershipTxs.Inc()
return nil
}
func (m *txMetrics) BaseTx(*txs.BaseTx) error {
m.numBaseTxs.Inc()
return nil
}