Skip to content

Commit

Permalink
add metric for tx count in block
Browse files Browse the repository at this point in the history
  • Loading branch information
Solovyov1796 committed Dec 25, 2024
1 parent efac775 commit 78a74bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions blockchain/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const (
blockHeightBehindPattern = "monitor/blockchain/block/height/behind/%v"
blockHeightUnhealthPattern = "monitor/blockchain/block/height/unhealth/%v"

// count of tx in block
blockTxCountPattern = "monitor/blockchain/block/tx/count"

// chain
chainForkPattern = "monitor/blockchain/fork/%v"
// ethermint rpc
Expand Down
12 changes: 11 additions & 1 deletion blockchain/serve.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package blockchain

import (
"fmt"
"net/url"
"sync"
"time"
Expand Down Expand Up @@ -69,6 +70,8 @@ func createMetricsForChain() {

metrics.GetOrRegisterGauge(failedTxCountUnhealthPattern).Update(0)
metrics.GetOrRegisterHistogram(failedTxCountPattern).Update(0)

metrics.GetOrRegisterHistogram(blockTxCountPattern).Update(0)
}

func monitorOnce(config *Config, nodes []*Node, validators []*Validator, mempool *Mempool) {
Expand Down Expand Up @@ -131,7 +134,12 @@ func countFailedTx(statusMap map[string]bool) int {

func monitorTxFailures(config *Config, nodes []*Node, txInfo *BlockTxInfo) {
if txInfo != nil {
if len(txInfo.TxHashes) > 0 {
blockTxCnt := len(txInfo.TxHashes)
metrics.GetOrRegisterHistogram(blockTxCountPattern).Update(int64(blockTxCnt))

logrus.Debug(fmt.Sprintf("Block (%d) tx count: %d", txInfo.Height, blockTxCnt))

if blockTxCnt > 0 {
index := int(time.Now().UnixNano() % int64(len(nodes)))
statusMap, err := nodes[index].FetchBlockReceiptStatus(config.NodeHeightReport.TimedCounterConfig, txInfo.Height)
if err != nil {
Expand Down Expand Up @@ -174,6 +182,8 @@ func monitorTxFailures(config *Config, nodes []*Node, txInfo *BlockTxInfo) {
}
}
}
} else {
metrics.GetOrRegisterHistogram(blockTxCountPattern).Update(0)
}
}

Expand Down

0 comments on commit 78a74bf

Please sign in to comment.