forked from cometbft/cometbft
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add block sync metrics (backport from main)
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package blocksync | ||
|
||
import ( | ||
"github.com/go-kit/kit/metrics" | ||
|
||
"github.com/cometbft/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)) | ||
} |