reth_stages_api/metrics/
sync_metrics.rs

1use crate::StageId;
2use reth_metrics::{metrics::Gauge, Metrics};
3use std::collections::HashMap;
4
5#[derive(Debug, Default)]
6pub(crate) struct SyncMetrics {
7    /// Stage metrics by stage.
8    pub(crate) stages: HashMap<StageId, StageMetrics>,
9}
10
11impl SyncMetrics {
12    /// Returns existing or initializes a new instance of [`StageMetrics`] for the provided
13    /// [`StageId`].
14    pub(crate) fn get_stage_metrics(&mut self, stage_id: StageId) -> &mut StageMetrics {
15        self.stages
16            .entry(stage_id)
17            .or_insert_with(|| StageMetrics::new_with_labels(&[("stage", stage_id.to_string())]))
18    }
19}
20
21#[derive(Metrics)]
22#[metrics(scope = "sync")]
23pub(crate) struct StageMetrics {
24    /// The block number of the last commit for a stage.
25    pub(crate) checkpoint: Gauge,
26    /// The number of processed entities of the last commit for a stage, if applicable.
27    pub(crate) entities_processed: Gauge,
28    /// The number of total entities of the last commit for a stage, if applicable.
29    pub(crate) entities_total: Gauge,
30    /// The number of seconds spent executing the stage and committing the data.
31    pub(crate) total_elapsed: Gauge,
32}