reth_prune/
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
use reth_metrics::{
    metrics::{Gauge, Histogram},
    Metrics,
};
use reth_prune_types::PruneSegment;
use std::collections::HashMap;

#[derive(Metrics)]
#[metrics(scope = "pruner")]
pub(crate) struct Metrics {
    /// Pruning duration
    pub(crate) duration_seconds: Histogram,
    #[metric(skip)]
    prune_segments: HashMap<PruneSegment, PrunerSegmentMetrics>,
}

impl Metrics {
    /// Returns existing or initializes a new instance of [`PrunerSegmentMetrics`] for the provided
    /// [`PruneSegment`].
    pub(crate) fn get_prune_segment_metrics(
        &mut self,
        segment: PruneSegment,
    ) -> &mut PrunerSegmentMetrics {
        self.prune_segments.entry(segment).or_insert_with(|| {
            PrunerSegmentMetrics::new_with_labels(&[("segment", segment.to_string())])
        })
    }
}

#[derive(Metrics)]
#[metrics(scope = "pruner.segments")]
pub(crate) struct PrunerSegmentMetrics {
    /// Pruning duration for this segment
    pub(crate) duration_seconds: Histogram,
    /// Highest pruned block per segment
    pub(crate) highest_pruned_block: Gauge,
}