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