forked from cometbft/cometbft
/
metrics.go
36 lines (30 loc) · 954 Bytes
/
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
package blocksync
import (
"github.com/go-kit/kit/metrics"
"github.com/zeu5/cometbft/types"
)
const (
// MetricsSubsystem is a subsystem shared by all metrics exposed by this
// package.
MetricsSubsystem = "blocksync"
)
//go:generate go run ../scripts/metricsgen -struct=Metrics
// Metrics contains metrics exposed by this package.
type Metrics struct {
// Whether or not a node is block syncing. 1 if yes, 0 if no.
Syncing metrics.Gauge
// Number of transactions in the latest block.
NumTxs metrics.Gauge
// Total number of transactions.
TotalTxs metrics.Gauge
// Size of the latest block.
BlockSizeBytes metrics.Gauge
// The height of the latest block.
LatestBlockHeight metrics.Gauge
}
func (m *Metrics) recordBlockMetrics(block *types.Block) {
m.NumTxs.Set(float64(len(block.Data.Txs)))
m.TotalTxs.Add(float64(len(block.Data.Txs)))
m.BlockSizeBytes.Set(float64(block.Size()))
m.LatestBlockHeight.Set(float64(block.Height))
}