Skip to content

Commit

Permalink
add block sync metrics (backport from main)
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Feb 25, 2024
1 parent 75f9d4f commit e8553ad
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
58 changes: 58 additions & 0 deletions blocksync/metrics.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions blocksync/metrics.go
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) {

Check failure on line 31 in blocksync/metrics.go

View workflow job for this annotation

GitHub Actions / golangci-lint

func `(*Metrics).recordBlockMetrics` is unused (unused)
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))
}

0 comments on commit e8553ad

Please sign in to comment.