fuel_core_metrics/
gas_price_metrics.rs

1use crate::global_registry;
2use prometheus_client::metrics::gauge::Gauge;
3use std::sync::OnceLock;
4
5#[derive(Debug)]
6pub struct GasPriceMetrics {
7    pub real_gas_price: Gauge,
8    pub exec_gas_price: Gauge,
9    pub da_gas_price: Gauge,
10    pub total_reward: Gauge,
11    pub total_known_costs: Gauge,
12    pub predicted_profit: Gauge,
13    pub unrecorded_bytes: Gauge,
14    pub latest_cost_per_byte: Gauge,
15    pub recorded_height: Gauge,
16}
17
18impl Default for GasPriceMetrics {
19    fn default() -> Self {
20        let real_gas_price = Gauge::default();
21        let exec_gas_price = Gauge::default();
22        let da_gas_price = Gauge::default();
23        let total_reward = Gauge::default();
24        let total_known_costs = Gauge::default();
25        let predicted_profit = Gauge::default();
26        let unrecorded_bytes = Gauge::default();
27        let latest_cost_per_byte = Gauge::default();
28        let recorded_height = Gauge::default();
29
30        let metrics = GasPriceMetrics {
31            real_gas_price,
32            exec_gas_price,
33            da_gas_price,
34            total_reward,
35            total_known_costs,
36            predicted_profit,
37            unrecorded_bytes,
38            latest_cost_per_byte,
39            recorded_height,
40        };
41
42        let mut registry = global_registry().registry.lock();
43        registry.register(
44            "gas_price_service_real_gas_price",
45            "The real gas price used on the most recent block",
46            metrics.real_gas_price.clone(),
47        );
48        registry.register(
49            "gas_price_service_exec_gas_price",
50            "The requested execution gas price for the next block",
51            metrics.exec_gas_price.clone(),
52        );
53        registry.register(
54            "gas_price_service_da_gas_price",
55            "The requested data availability gas price for the next block",
56            metrics.da_gas_price.clone(),
57        );
58        registry.register(
59            "gas_price_service_total_reward",
60            "The total reward received from DA gas price fees",
61            metrics.total_reward.clone(),
62        );
63        registry.register(
64            "gas_price_service_total_known_costs",
65            "The total known costs for committing L2 blocks to DA",
66            metrics.total_known_costs.clone(),
67        );
68        registry.register(
69            "gas_price_service_predicted_profit",
70            "The predicted profit based on the rewards, known costs, and predicted costs from price per byte",
71            metrics.predicted_profit.clone(),
72        );
73        registry.register(
74            "gas_price_service_unrecorded_bytes",
75            "The total bytes of all L2 blocks waiting to be recorded on DA",
76            metrics.unrecorded_bytes.clone(),
77        );
78        registry.register(
79            "gas_price_service_latest_cost_per_byte",
80            "The latest cost per byte to record L2 blocks on DA",
81            metrics.latest_cost_per_byte.clone(),
82        );
83
84        registry.register(
85            "gas_price_service_recorded_height",
86            "The height of the latest L2 block recorded on DA",
87            metrics.recorded_height.clone(),
88        );
89
90        metrics
91    }
92}
93
94static GAS_PRICE_METRICS: OnceLock<GasPriceMetrics> = OnceLock::new();
95
96pub fn gas_price_metrics() -> &'static GasPriceMetrics {
97    GAS_PRICE_METRICS.get_or_init(GasPriceMetrics::default)
98}