feat(txpool): add sub-pools length and size metrics (#2598)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Léo Vincent
2023-05-09 15:52:20 +02:00
committed by GitHub
parent 07983239eb
commit c0cbb6a473
3 changed files with 37 additions and 2 deletions

View File

@ -1,6 +1,6 @@
//! Transaction pool metrics. //! Transaction pool metrics.
use metrics::Counter; use metrics::{Counter, Gauge};
use reth_metrics_derive::Metrics; use reth_metrics_derive::Metrics;
/// Transaction pool metrics /// Transaction pool metrics
@ -13,4 +13,19 @@ pub struct TxPoolMetrics {
pub(crate) invalid_transactions: Counter, pub(crate) invalid_transactions: Counter,
/// Number of removed transactions from the pool /// Number of removed transactions from the pool
pub(crate) removed_transactions: Counter, pub(crate) removed_transactions: Counter,
/// Number of transactions in the pending sub-pool
pub(crate) pending_pool_transactions: Gauge,
/// Total amount of memory used by the transactions in the pending sub-pool in bytes
pub(crate) pending_pool_size_bytes: Gauge,
/// Number of transactions in the basefee sub-pool
pub(crate) basefee_pool_transactions: Gauge,
/// Total amount of memory used by the transactions in the basefee sub-pool in bytes
pub(crate) basefee_pool_size_bytes: Gauge,
/// Number of transactions in the queued sub-pool
pub(crate) queued_pool_transactions: Gauge,
/// Total amount of memory used by the transactions in the queued sub-pool in bytes
pub(crate) queued_pool_size_bytes: Gauge,
} }

View File

@ -253,9 +253,23 @@ impl<T: TransactionOrdering> TxPool<T> {
// Process the sub-pool updates // Process the sub-pool updates
let UpdateOutcome { promoted, discarded } = self.process_updates(updates); let UpdateOutcome { promoted, discarded } = self.process_updates(updates);
// update the metrics after the update
self.update_size_metrics();
OnNewCanonicalStateOutcome { block_hash, mined: mined_transactions, promoted, discarded } OnNewCanonicalStateOutcome { block_hash, mined: mined_transactions, promoted, discarded }
} }
/// Update sub-pools size metrics.
pub(crate) fn update_size_metrics(&mut self) {
let stats = self.size();
self.metrics.pending_pool_transactions.set(stats.pending as f64);
self.metrics.pending_pool_size_bytes.set(stats.pending_size as f64);
self.metrics.basefee_pool_transactions.set(stats.basefee as f64);
self.metrics.basefee_pool_size_bytes.set(stats.basefee_size as f64);
self.metrics.queued_pool_transactions.set(stats.queued as f64);
self.metrics.queued_pool_size_bytes.set(stats.queued_size as f64);
}
/// Adds the transaction into the pool. /// Adds the transaction into the pool.
/// ///
/// This pool consists of two three-pools: `Queued`, `Pending` and `BaseFee`. /// This pool consists of two three-pools: `Queued`, `Pending` and `BaseFee`.

View File

@ -75,8 +75,14 @@ This list may be non-exhaustive.
#### Component: Transaction Pool #### Component: Transaction Pool
- `transaction_pool.inserted_transactions`: Number of transactions inserted in the pool - `transaction_pool.inserted_transactions`: Number of transactions inserted in the pool
- `transaction_pool.invalid_transactions`: Number of invalid transactions - `transaction_pool.invalid_transactions`: Number of invalid transactions
- `transaction_pool.removed_transactions`: Number of removed transactions from the pool - `transaction_pool.removed_transactions`: Number of removed transactions from the pool
- `transaction_pool.pending_pool_transactions`: Number of transactions in the pending sub-pool
- `transaction_pool.pending_pool_size_bytes`: Total amount of memory used by the transactions in the pending sub-pool in bytes
- `transaction_pool.basefee_pool_transactions`: Number of transactions in the basefee sub-pool
- `transaction_pool.basefee_pool_size_bytes`: Total amount of memory used by the transactions in the basefee sub-pool in bytes
- `transaction_pool.queued_pool_transactions`: Number of transactions in the queued sub-pool
- `transaction_pool.queued_pool_size_bytes`: Total amount of memory used by the transactions in the queued sub-pool in bytes
#### Component: Network #### Component: Network