fuel_core_metrics/
gas_price_metrics.rs

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use crate::global_registry;
use prometheus_client::metrics::gauge::Gauge;
use std::sync::OnceLock;

#[derive(Debug)]
pub struct GasPriceMetrics {
    pub real_gas_price: Gauge,
    pub exec_gas_price: Gauge,
    pub da_gas_price: Gauge,
    pub total_reward: Gauge,
    pub total_known_costs: Gauge,
    pub predicted_profit: Gauge,
    pub unrecorded_bytes: Gauge,
    pub latest_cost_per_byte: Gauge,
    pub recorded_height: Gauge,
}

impl Default for GasPriceMetrics {
    fn default() -> Self {
        let real_gas_price = Gauge::default();
        let exec_gas_price = Gauge::default();
        let da_gas_price = Gauge::default();
        let total_reward = Gauge::default();
        let total_known_costs = Gauge::default();
        let predicted_profit = Gauge::default();
        let unrecorded_bytes = Gauge::default();
        let latest_cost_per_byte = Gauge::default();
        let recorded_height = Gauge::default();

        let metrics = GasPriceMetrics {
            real_gas_price,
            exec_gas_price,
            da_gas_price,
            total_reward,
            total_known_costs,
            predicted_profit,
            unrecorded_bytes,
            latest_cost_per_byte,
            recorded_height,
        };

        let mut registry = global_registry().registry.lock();
        registry.register(
            "gas_price_service_real_gas_price",
            "The real gas price used on the most recent block",
            metrics.real_gas_price.clone(),
        );
        registry.register(
            "gas_price_service_exec_gas_price",
            "The requested execution gas price for the next block",
            metrics.exec_gas_price.clone(),
        );
        registry.register(
            "gas_price_service_da_gas_price",
            "The requested data availability gas price for the next block",
            metrics.da_gas_price.clone(),
        );
        registry.register(
            "gas_price_service_total_reward",
            "The total reward received from DA gas price fees",
            metrics.total_reward.clone(),
        );
        registry.register(
            "gas_price_service_total_known_costs",
            "The total known costs for committing L2 blocks to DA",
            metrics.total_known_costs.clone(),
        );
        registry.register(
            "gas_price_service_predicted_profit",
            "The predicted profit based on the rewards, known costs, and predicted costs from price per byte",
            metrics.predicted_profit.clone(),
        );
        registry.register(
            "gas_price_service_unrecorded_bytes",
            "The total bytes of all L2 blocks waiting to be recorded on DA",
            metrics.unrecorded_bytes.clone(),
        );
        registry.register(
            "gas_price_service_latest_cost_per_byte",
            "The latest cost per byte to record L2 blocks on DA",
            metrics.latest_cost_per_byte.clone(),
        );

        registry.register(
            "gas_price_service_recorded_height",
            "The height of the latest L2 block recorded on DA",
            metrics.recorded_height.clone(),
        );

        metrics
    }
}

static GAS_PRICE_METRICS: OnceLock<GasPriceMetrics> = OnceLock::new();

pub fn gas_price_metrics() -> &'static GasPriceMetrics {
    GAS_PRICE_METRICS.get_or_init(GasPriceMetrics::default)
}