Skip to content

Commit 07b2734

Browse files
committed
new stats collector
1 parent 9be06ee commit 07b2734

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

core/txpool/queue.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func (q *queue) add(tx *types.Transaction) (*common.Hash, error) {
120120
from, _ := types.Sender(q.signer, tx) // already validated
121121
if q.queued[from] == nil {
122122
q.queued[from] = newList(false)
123+
queuedAddrsGauge.Inc(1)
123124
}
124125
inserted, old := q.queued[from].Add(tx, q.config.PriceBump)
125126
if !inserted {
@@ -196,6 +197,7 @@ func (q *queue) promoteExecutables(accounts []common.Address, gasLimit uint64, c
196197
if list.Empty() {
197198
delete(q.queued, addr)
198199
delete(q.beats, addr)
200+
queuedAddrsGauge.Dec(1)
199201
removedAddresses = append(removedAddresses, addr)
200202
}
201203
}

core/txpool/txpool.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ var (
134134

135135
slotsGauge = metrics.NewRegisteredGauge("txpool/slots", nil)
136136

137+
pendingAddrsGauge = metrics.NewRegisteredGauge("txpool/pending/accounts", nil)
138+
queuedAddrsGauge = metrics.NewRegisteredGauge("txpool/queued/accounts", nil)
139+
137140
reheapTimer = metrics.NewRegisteredTimer("txpool/reheap", nil)
138141
)
139142

@@ -863,6 +866,7 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
863866
// Try to insert the transaction into the pending queue
864867
if pool.pending[addr] == nil {
865868
pool.pending[addr] = newList(true)
869+
pendingAddrsGauge.Inc(1)
866870
}
867871
list := pool.pending[addr]
868872

@@ -1073,6 +1077,7 @@ func (pool *TxPool) removeTx(hash common.Hash, outofbound bool, unreserve bool)
10731077
// If no more pending transactions are left, remove the list
10741078
if pending.Empty() {
10751079
delete(pool.pending, addr)
1080+
pendingAddrsGauge.Dec(1)
10761081
}
10771082
// Postpone any invalidated transactions
10781083
for _, tx := range invalids {
@@ -1365,6 +1370,9 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
13651370
pool.currentState = statedb
13661371
pool.pendingNonces = newNoncer(statedb)
13671372

1373+
pendingAddrsGauge.Update(0)
1374+
queuedAddrsGauge.Update(0)
1375+
13681376
// Inject any transactions discarded due to reorgs
13691377
log.Debug("Reinjecting stale transactions", "count", len(reinject))
13701378
core.SenderCacher.Recover(pool.signer, reinject)
@@ -1568,6 +1576,7 @@ func (pool *TxPool) demoteUnexecutables() {
15681576
// Delete the entire pending entry if it became empty.
15691577
if list.Empty() {
15701578
delete(pool.pending, addr)
1579+
pendingAddrsGauge.Dec(1)
15711580
if _, ok := pool.queue.get(addr); !ok {
15721581
pool.reserver.Release(addr)
15731582
}

0 commit comments

Comments
 (0)