Skip to content

Commit

Permalink
add monitor block height metrics (#3176)
Browse files Browse the repository at this point in the history
* add block_height metrics

* add monitor block_height metrics

* fix ut

---------

Co-authored-by: KamiD <[email protected]>
  • Loading branch information
FineKe and KamiD authored Jun 19, 2023
1 parent 0046c91 commit fccac7b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions libs/tendermint/blockchain/v0/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ FOR_LOOP:
// TODO: same thing for app - but we would need a way to
// get the hash without persisting the state
var err error

bcR.curState, _, err = bcR.blockExec.ApplyBlockWithTrace(bcR.curState, firstID, first) // rpc
if err != nil {
// TODO This is bad, are we zombie?
Expand Down
2 changes: 2 additions & 0 deletions libs/tendermint/state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func (blockExec *BlockExecutor) ApplyBlock(
f, t := PprofStart()
defer PprofEnd(int(block.Height), f, t)
}

trc := trace.NewTracer(trace.ApplyBlock)
trc.EnableSummary()
trc.SetWorkloadStatistic(trace.GetApplyBlockWorkloadSttistic())
Expand All @@ -224,6 +225,7 @@ func (blockExec *BlockExecutor) ApplyBlock(
now := time.Now().UnixNano()
blockExec.metrics.IntervalTime.Set(float64(now-blockExec.metrics.lastBlockTime) / 1e6)
blockExec.metrics.lastBlockTime = now
blockExec.metrics.CommittedHeight.Set(float64(block.Height))
}()

if err := blockExec.ValidateBlock(state, block); err != nil {
Expand Down
9 changes: 9 additions & 0 deletions libs/tendermint/state/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type Metrics struct {
AbciTime metrics.Gauge
// Time during commiting app state
CommitTime metrics.Gauge

CommittedHeight metrics.Gauge
}

// PrometheusMetrics returns Metrics build using Prometheus client library.
Expand Down Expand Up @@ -64,6 +66,12 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
Name: "block_commit_time",
Help: "Time during commiting app state in ms.",
}, labels).With(labelsAndValues...),
CommittedHeight: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: namespace,
Subsystem: MetricsSubsystem,
Name: "monitor_block_height",
Help: "The block height.",
}, labels).With(labelsAndValues...),
}
}

Expand All @@ -75,5 +83,6 @@ func NopMetrics() *Metrics {
lastBlockTime: time.Now().UnixNano(),
AbciTime: discard.NewGauge(),
CommitTime: discard.NewGauge(),
CommittedHeight: discard.NewGauge(),
}
}

0 comments on commit fccac7b

Please sign in to comment.