-
Notifications
You must be signed in to change notification settings - Fork 662
/
block_metrics.go
87 lines (73 loc) · 2.31 KB
/
block_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
// Copyright (C) 2019-2021, 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/blocks"
)
var _ blocks.Visitor = &blockMetrics{}
type blockMetrics struct {
txMetrics *txMetrics
numAbortBlocks,
numAtomicBlocks,
numCommitBlocks,
numProposalBlocks,
numStandardBlocks prometheus.Counter
}
func newBlockMetrics(
namespace string,
registerer prometheus.Registerer,
) (*blockMetrics, error) {
txMetrics, err := newTxMetrics(namespace, registerer)
errs := wrappers.Errs{Err: err}
m := &blockMetrics{
txMetrics: txMetrics,
numAbortBlocks: newBlockMetric(namespace, "abort", registerer, &errs),
numAtomicBlocks: newBlockMetric(namespace, "atomic", registerer, &errs),
numCommitBlocks: newBlockMetric(namespace, "commit", registerer, &errs),
numProposalBlocks: newBlockMetric(namespace, "proposal", registerer, &errs),
numStandardBlocks: newBlockMetric(namespace, "standard", registerer, &errs),
}
return m, errs.Err
}
func newBlockMetric(
namespace string,
blockName string,
registerer prometheus.Registerer,
errs *wrappers.Errs,
) prometheus.Counter {
blockMetric := prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: fmt.Sprintf("%s_blks_accepted", blockName),
Help: fmt.Sprintf("Number of %s blocks accepted", blockName),
})
errs.Add(registerer.Register(blockMetric))
return blockMetric
}
func (m *blockMetrics) ApricotProposalBlock(b *blocks.ApricotProposalBlock) error {
m.numProposalBlocks.Inc()
return b.Tx.Unsigned.Visit(m.txMetrics)
}
func (m *blockMetrics) ApricotAtomicBlock(b *blocks.ApricotAtomicBlock) error {
m.numAtomicBlocks.Inc()
return b.Tx.Unsigned.Visit(m.txMetrics)
}
func (m *blockMetrics) ApricotStandardBlock(b *blocks.ApricotStandardBlock) error {
m.numStandardBlocks.Inc()
for _, tx := range b.Transactions {
if err := tx.Unsigned.Visit(m.txMetrics); err != nil {
return err
}
}
return nil
}
func (m *blockMetrics) ApricotCommitBlock(*blocks.ApricotCommitBlock) error {
m.numCommitBlocks.Inc()
return nil
}
func (m *blockMetrics) ApricotAbortBlock(*blocks.ApricotAbortBlock) error {
m.numAbortBlocks.Inc()
return nil
}