Skip to main content

espresso_node/persistence/
persistence_metrics.rs

1use hotshot_types::traits::metrics::{Histogram, Metrics, NoMetrics};
2
3/// Metrics for the persistence layer
4#[derive(Clone, Debug)]
5pub struct PersistenceMetricsValue {
6    /// Time taken by the underlying storage to execute the command that appends a VID
7    pub internal_append_vid_duration: Box<dyn Histogram>,
8    /// Time taken by the underlying storage to execute the command that appends DA
9    pub internal_append_da_duration: Box<dyn Histogram>,
10    /// Time taken by the underlying storage to execute the command that appends DA 2
11    pub internal_append_da2_duration: Box<dyn Histogram>,
12    /// Time taken by the underlying storage to execute the command that appends Quorum Proposal 2
13    pub internal_append_quorum2_duration: Box<dyn Histogram>,
14    /// Time taken by a full decide-event pass (event generation plus garbage collection),
15    /// including any lock or transaction waits. On the fs backend this pass holds the exclusive
16    /// persistence write lock, so it bounds how long concurrent appends can block.
17    pub internal_process_decided_events_duration: Box<dyn Histogram>,
18}
19
20impl PersistenceMetricsValue {
21    /// Create a new instance of this [`PersistenceMetricsValue`] struct, setting all the counters and gauges
22    #[must_use]
23    pub fn new(metrics: &dyn Metrics) -> Self {
24        Self {
25            internal_append_vid_duration: metrics.create_histogram(
26                String::from("internal_append_vid_duration"),
27                Some("seconds".to_string()),
28            ),
29            internal_append_da_duration: metrics.create_histogram(
30                String::from("internal_append_da_duration"),
31                Some("seconds".to_string()),
32            ),
33            internal_append_da2_duration: metrics.create_histogram(
34                String::from("internal_append_da2_duration"),
35                Some("seconds".to_string()),
36            ),
37            internal_append_quorum2_duration: metrics.create_histogram(
38                String::from("internal_append_quorum2_duration"),
39                Some("seconds".to_string()),
40            ),
41            internal_process_decided_events_duration: metrics.create_histogram(
42                String::from("internal_process_decided_events_duration"),
43                Some("seconds".to_string()),
44            ),
45        }
46    }
47}
48
49impl Default for PersistenceMetricsValue {
50    fn default() -> Self {
51        Self::new(&*NoMetrics::boxed())
52    }
53}