fuel_metrics/
txpool_metrics.rs

1use lazy_static::lazy_static;
2use prometheus_client::{
3    metrics::histogram::Histogram,
4    registry::Registry,
5};
6use std::{
7    boxed::Box,
8    default::Default,
9};
10
11pub struct TxPoolMetrics {
12    // Attaches each Metric to the Registry
13    pub registry: Registry,
14    pub gas_price_histogram: Histogram,
15    pub tx_size_histogram: Histogram,
16}
17
18impl Default for TxPoolMetrics {
19    fn default() -> Self {
20        let registry = Registry::default();
21
22        let gas_prices = Vec::new();
23
24        let gas_price_histogram = Histogram::new(gas_prices.into_iter());
25
26        let tx_sizes = Vec::new();
27
28        let tx_size_histogram = Histogram::new(tx_sizes.into_iter());
29
30        let mut metrics = TxPoolMetrics {
31            registry,
32            gas_price_histogram,
33            tx_size_histogram,
34        };
35
36        metrics.registry.register(
37            "Tx_Gas_Price_Histogram",
38            "A Histogram keeping track of all gas prices for each tx in the mempool",
39            Box::new(metrics.gas_price_histogram.clone()),
40        );
41
42        metrics.registry.register(
43            "Tx_Size_Histogram",
44            "A Histogram keeping track of the size of txs",
45            Box::new(metrics.tx_size_histogram.clone()),
46        );
47
48        metrics
49    }
50}
51
52lazy_static! {
53    pub static ref TXPOOL_METRICS: TxPoolMetrics = TxPoolMetrics::default();
54}