-
Notifications
You must be signed in to change notification settings - Fork 664
/
tx_metrics.go
110 lines (93 loc) · 3.06 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
// Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package platformvm
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{}
type txMetrics struct {
numAddDelegatorTxs,
numAddSubnetValidatorTxs,
numAddValidatorTxs,
numAdvanceTimeTxs,
numCreateChainTxs,
numCreateSubnetTxs,
numExportTxs,
numImportTxs,
numRewardValidatorTxs,
numTransformSubnetTxs,
numAddGeneralValidatorTxs 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),
numTransformSubnetTxs: newTxMetric(namespace, "transform_subnet", registerer, &errs),
numAddGeneralValidatorTxs: newTxMetric(namespace, "add_general_validator", 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: fmt.Sprintf("%s_txs_accepted", txName),
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(tx *txs.ImportTx) error {
m.numImportTxs.Inc()
return nil
}
func (m *txMetrics) ExportTx(tx *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
}