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 pub(crate) stages: HashMap<StageId, StageMetrics>,
8}
9
10impl SyncMetrics {
11 /// Returns existing or initializes a new instance of [`StageMetrics`] for the provided
12 /// [`StageId`].
13 pub(crate) fn get_stage_metrics(&mut self, stage_id: StageId) -> &mut StageMetrics {
14 self.stages
15 .entry(stage_id)
16 .or_insert_with(|| StageMetrics::new_with_labels(&[("stage", stage_id.to_string())]))
17 }
18}
19
20#[derive(Metrics)]
21#[metrics(scope = "sync")]
22pub(crate) struct StageMetrics {
23 /// The block number of the last commit for a stage.
24 pub(crate) checkpoint: Gauge,
25 /// The number of processed entities of the last commit for a stage, if applicable.
26 pub(crate) entities_processed: Gauge,
27 /// The number of total entities of the last commit for a stage, if applicable.
28 pub(crate) entities_total: Gauge,
29}