From e25064809b12da3f482aa2cd08b669fdb6e2fc9a Mon Sep 17 00:00:00 2001 From: Yiming Zang <50607998+yzang2019@users.noreply.github.com> Date: Mon, 1 Apr 2024 21:37:23 +0800 Subject: [PATCH] Add metrics for mempool size changes (#220) --- internal/mempool/mempool.go | 2 ++ internal/mempool/metrics.gen.go | 14 ++++++++++++++ internal/mempool/metrics.go | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/internal/mempool/mempool.go b/internal/mempool/mempool.go index 4f70e9aa0..6acdcf408 100644 --- a/internal/mempool/mempool.go +++ b/internal/mempool/mempool.go @@ -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 } @@ -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) diff --git a/internal/mempool/metrics.gen.go b/internal/mempool/metrics.gen.go index c5a44f029..cfff9ad4c 100644 --- a/internal/mempool/metrics.gen.go +++ b/internal/mempool/metrics.gen.go @@ -64,6 +64,18 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { Name: "recheck_times", Help: "Number of times transactions are rechecked in the mempool.", }, labels).With(labelsAndValues...), + RemovedTxs: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ + Namespace: namespace, + Subsystem: MetricsSubsystem, + Name: "removed_txs", + Help: "Number of removed tx from mempool", + }, labels).With(labelsAndValues...), + InsertedTxs: prometheus.NewCounterFrom(stdprometheus.CounterOpts{ + Namespace: namespace, + Subsystem: MetricsSubsystem, + Name: "inserted_txs", + Help: "Number of txs inserted to mempool", + }, labels).With(labelsAndValues...), } } @@ -77,5 +89,7 @@ func NopMetrics() *Metrics { EvictedTxs: discard.NewCounter(), ExpiredTxs: discard.NewCounter(), RecheckTimes: discard.NewCounter(), + RemovedTxs: discard.NewCounter(), + InsertedTxs: discard.NewCounter(), } } diff --git a/internal/mempool/metrics.go b/internal/mempool/metrics.go index eb296182d..fb68f7918 100644 --- a/internal/mempool/metrics.go +++ b/internal/mempool/metrics.go @@ -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 }