Skip to content

Commit

Permalink
Add metrics for mempool size changes (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
yzang2019 authored and udpatil committed Apr 16, 2024
1 parent 23751c8 commit 4b01444
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ func (txmp *TxMempool) insertTx(wtx *WrappedTx, updatePriorityIndex bool) bool {
gossipEl := txmp.gossipIndex.PushBack(wtx)
wtx.gossipEl = gossipEl

txmp.metrics.InsertedTxs.Add(1)
atomic.AddInt64(&txmp.sizeBytes, int64(wtx.Size()))
return true
}
Expand All @@ -911,6 +912,7 @@ func (txmp *TxMempool) removeTx(wtx *WrappedTx, removeFromCache bool, shouldReen
txmp.gossipIndex.Remove(wtx.gossipEl)
wtx.gossipEl.DetachPrev()

txmp.metrics.RemovedTxs.Add(1)
atomic.AddInt64(&txmp.sizeBytes, int64(-wtx.Size()))

wtx.removeHandler(removeFromCache)
Expand Down
14 changes: 14 additions & 0 deletions internal/mempool/metrics.gen.go

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

6 changes: 6 additions & 0 deletions internal/mempool/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ type Metrics struct {

// Number of times transactions are rechecked in the mempool.
RecheckTimes metrics.Counter

// Number of removed tx from mempool
RemovedTxs metrics.Counter

// Number of txs inserted to mempool
InsertedTxs metrics.Counter
}

0 comments on commit 4b01444

Please sign in to comment.