kona_node_service/metrics/
mod.rs

1//! Metrics for the node service
2
3/// Container for metrics.
4#[derive(Debug, Clone)]
5pub struct Metrics;
6
7impl Metrics {
8    /// Identifier for the counter that tracks the number of times the L1 has reorganized.
9    pub const L1_REORG_COUNT: &str = "kona_node_l1_reorg_count";
10
11    /// Identifier for the counter that tracks the L1 origin of the derivation pipeline.
12    pub const DERIVATION_L1_ORIGIN: &str = "kona_node_derivation_l1_origin";
13
14    /// Identifier for the counter of critical derivation errors (strictly for alerting.)
15    pub const DERIVATION_CRITICAL_ERROR: &str = "kona_node_derivation_critical_errors";
16
17    /// Identifier for the counter that tracks sequencer state flags.
18    pub const SEQUENCER_STATE: &str = "kona_node_sequencer_state";
19
20    /// Gauge for the sequencer's attributes builder duration.
21    pub const SEQUENCER_ATTRIBUTES_BUILDER_DURATION: &str =
22        "kona_node_sequencer_attributes_build_duration";
23
24    /// Gauge for the sequencer's block building job duration.
25    pub const SEQUENCER_BLOCK_BUILDING_JOB_DURATION: &str =
26        "kona_node_sequencer_block_building_duration";
27
28    /// Gauge for the sequencer's conductor commitment duration.
29    pub const SEQUENCER_CONDUCTOR_COMMITMENT_DURATION: &str =
30        "kona_node_sequencer_conductor_commitment_duration";
31
32    /// Initializes metrics for the node service.
33    ///
34    /// This does two things:
35    /// * Describes various metrics.
36    /// * Initializes metrics to 0 so they can be queried immediately.
37    #[cfg(feature = "metrics")]
38    pub fn init() {
39        Self::describe();
40        Self::zero();
41    }
42
43    /// Describes metrics used in [`kona-node-service`][crate].
44    #[cfg(feature = "metrics")]
45    pub fn describe() {
46        // L1 reorg count
47        metrics::describe_counter!(Self::L1_REORG_COUNT, metrics::Unit::Count, "L1 reorg count");
48
49        // Derivation L1 origin
50        metrics::describe_counter!(Self::DERIVATION_L1_ORIGIN, "Derivation pipeline L1 origin");
51
52        // Derivation critical error
53        metrics::describe_counter!(
54            Self::DERIVATION_CRITICAL_ERROR,
55            "Critical errors in the derivation pipeline"
56        );
57
58        // Sequencer state
59        metrics::describe_counter!(Self::SEQUENCER_STATE, "Tracks sequencer state flags");
60
61        // Sequencer attributes builder duration
62        metrics::describe_gauge!(
63            Self::SEQUENCER_ATTRIBUTES_BUILDER_DURATION,
64            "Duration of the sequencer attributes builder"
65        );
66
67        // Sequencer block building job duration
68        metrics::describe_gauge!(
69            Self::SEQUENCER_BLOCK_BUILDING_JOB_DURATION,
70            "Duration of the sequencer block building job"
71        );
72
73        // Sequencer conductor commitment duration
74        metrics::describe_gauge!(
75            Self::SEQUENCER_CONDUCTOR_COMMITMENT_DURATION,
76            "Duration of the sequencer conductor commitment"
77        );
78    }
79
80    /// Initializes metrics to `0` so they can be queried immediately by consumers of prometheus
81    /// metrics.
82    #[cfg(feature = "metrics")]
83    pub fn zero() {
84        // L1 reorg reset count
85        kona_macros::set!(counter, Self::L1_REORG_COUNT, 0);
86
87        // Derivation critical error
88        kona_macros::set!(counter, Self::DERIVATION_CRITICAL_ERROR, 0);
89    }
90}