fuel_core_metrics/
txpool_metrics.rs1use crate::{
2 buckets::{
3 buckets,
4 Buckets,
5 },
6 global_registry,
7};
8use prometheus_client::metrics::{
9 gauge::Gauge,
10 histogram::Histogram,
11};
12use std::sync::OnceLock;
13
14pub struct TxPoolMetrics {
15 pub tx_size: Histogram,
17 pub number_of_transactions: Gauge,
19 pub number_of_transactions_pending_verification: Gauge,
21 pub number_of_executable_transactions: Gauge,
23 pub transaction_time_in_txpool_secs: Histogram,
25 pub transaction_insertion_time_in_thread_pool_microseconds: Histogram,
27 pub select_transactions_time_microseconds: Histogram,
29}
30
31impl Default for TxPoolMetrics {
32 fn default() -> Self {
33 let tx_size = Histogram::new(buckets(Buckets::TransactionSize));
34 let transaction_time_in_txpool_secs =
35 Histogram::new(buckets(Buckets::TransactionTimeInTxpool));
36 let select_transactions_time_microseconds =
37 Histogram::new(buckets(Buckets::SelectTransactionsTime));
38 let transaction_insertion_time_in_thread_pool_microseconds =
39 Histogram::new(buckets(Buckets::TransactionInsertionTimeInThreadPool));
40
41 let number_of_transactions = Gauge::default();
42 let number_of_transactions_pending_verification = Gauge::default();
43 let number_of_executable_transactions = Gauge::default();
44
45 let metrics = TxPoolMetrics {
46 tx_size,
47 number_of_transactions,
48 number_of_transactions_pending_verification,
49 number_of_executable_transactions,
50 transaction_time_in_txpool_secs,
51 transaction_insertion_time_in_thread_pool_microseconds,
52 select_transactions_time_microseconds,
53 };
54
55 let mut registry = global_registry().registry.lock();
56 registry.register(
57 "txpool_tx_size",
58 "The size of transactions in the txpool",
59 metrics.tx_size.clone(),
60 );
61
62 registry.register(
63 "txpool_tx_time_in_txpool_seconds",
64 "The time spent by a transaction in the txpool in seconds",
65 metrics.transaction_time_in_txpool_secs.clone(),
66 );
67
68 registry.register(
69 "txpool_number_of_transactions",
70 "The number of transactions in the txpool",
71 metrics.number_of_transactions.clone(),
72 );
73
74 registry.register(
75 "txpool_number_of_executable_transactions",
76 "The number of executable transactions in the txpool",
77 metrics.number_of_executable_transactions.clone(),
78 );
79
80 registry.register(
81 "txpool_number_of_transactions_pending_verification",
82 "The number of transactions pending verification before entering the txpool",
83 metrics.number_of_transactions_pending_verification.clone(),
84 );
85
86 registry.register(
87 "txpool_select_transactions_time_microseconds",
88 "The time it took to select transactions for inclusion in a block in microseconds",
89 metrics.select_transactions_time_microseconds.clone(),
90 );
91
92 registry.register(
93 "txpool_transaction_insertion_time_in_thread_pool_microseconds",
94 "The time it took to insert a transaction in the txpool in microseconds",
95 metrics
96 .transaction_insertion_time_in_thread_pool_microseconds
97 .clone(),
98 );
99
100 metrics
101 }
102}
103
104static TXPOOL_METRICS: OnceLock<TxPoolMetrics> = OnceLock::new();
105pub fn txpool_metrics() -> &'static TxPoolMetrics {
106 TXPOOL_METRICS.get_or_init(TxPoolMetrics::default)
107}