diff --git a/cmd/thor/node/metrics.go b/cmd/thor/node/metrics.go index a6d56f2dc..b7c2ec2c6 100644 --- a/cmd/thor/node/metrics.go +++ b/cmd/thor/node/metrics.go @@ -10,10 +10,12 @@ import ( ) var ( - metricBlockProcessedCount = metrics.LazyLoadCounterVec("block_processed_count", []string{"type", "success"}) - metricBlockProcessedTxs = metrics.LazyLoadGaugeVec("block_processed_tx_gauge", []string{"type"}) - metricBlockProcessedGas = metrics.LazyLoadGaugeVec("block_processed_gas_gauge", []string{"type"}) - metricBlockProcessedDuration = metrics.LazyLoadHistogram("block_processed_duration_ms", metrics.Bucket10s) - metricChainForkCount = metrics.LazyLoadCounter("chain_fork_count") - metricChainForkSize = metrics.LazyLoadGauge("chain_fork_gauge") + metricBlockProcessedCount = metrics.LazyLoadCounterVec("block_processed_count", []string{"type", "success"}) + metricBlockProcessedTxs = metrics.LazyLoadGaugeVec("block_processed_tx_gauge", []string{"type"}) + metricBlockProcessedGas = metrics.LazyLoadGaugeVec("block_processed_gas_gauge", []string{"type"}) + metricBlockProcessedDuration = metrics.LazyLoadHistogram("block_processed_duration_ms", metrics.Bucket10s) + metricChainForkCount = metrics.LazyLoadCounter("chain_fork_count") + metricChainForkSize = metrics.LazyLoadGauge("chain_fork_gauge") + metricBlockProcessingLockCount = metrics.LazyLoadCounterVec("block_processing_lock_count", []string{"type"}) + metricBlockProcessingLockDuration = metrics.LazyLoadHistogram("block_processing_lock_duration_ms", metrics.Bucket10s) ) diff --git a/cmd/thor/node/node.go b/cmd/thor/node/node.go index 251e421b0..2b0eb36b3 100644 --- a/cmd/thor/node/node.go +++ b/cmd/thor/node/node.go @@ -274,8 +274,15 @@ func (n *Node) txStashLoop(ctx context.Context) { // guardBlockProcessing adds lock on block processing and maintains block conflicts. func (n *Node) guardBlockProcessing(blockNum uint32, process func(conflicts uint32) error) error { + startTime := mclock.Now() n.processLock.Lock() - defer n.processLock.Unlock() + metricBlockProcessingLockCount().AddWithLabel(1, map[string]string{"type": "acquired"}) + defer func() { + n.processLock.Unlock() + metricBlockProcessingLockCount().AddWithLabel(1, map[string]string{"type": "released"}) + timeElapsed := mclock.Now() - startTime + metricBlockProcessingLockDuration().Observe(time.Duration(timeElapsed).Milliseconds()) + }() if blockNum > n.maxBlockNum { if blockNum > n.maxBlockNum+1 {