iota_core/checkpoints/
metrics.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use std::sync::Arc;
6
7use prometheus::{
8    Histogram, IntCounter, IntCounterVec, IntGauge, IntGaugeVec, Registry,
9    register_histogram_with_registry, register_int_counter_vec_with_registry,
10    register_int_counter_with_registry, register_int_gauge_vec_with_registry,
11    register_int_gauge_with_registry,
12};
13
14pub struct CheckpointMetrics {
15    pub last_certified_checkpoint: IntGauge,
16    pub last_constructed_checkpoint: IntGauge,
17    pub checkpoint_errors: IntCounter,
18    pub transactions_included_in_checkpoint: IntCounter,
19    pub checkpoint_roots_count: IntCounter,
20    pub checkpoint_participation: IntCounterVec,
21    pub last_received_checkpoint_signatures: IntGaugeVec,
22    pub last_sent_checkpoint_signature: IntGauge,
23    pub last_skipped_checkpoint_signature_submission: IntGauge,
24    pub last_ignored_checkpoint_signature_received: IntGauge,
25    pub highest_accumulated_epoch: IntGauge,
26    pub checkpoint_creation_latency: Histogram,
27    pub remote_checkpoint_forks: IntCounter,
28    pub split_brain_checkpoint_forks: IntCounter,
29    pub last_created_checkpoint_age: Histogram,
30    pub last_certified_checkpoint_age: Histogram,
31}
32
33impl CheckpointMetrics {
34    pub fn new(registry: &Registry) -> Arc<Self> {
35        let this = Self {
36            last_certified_checkpoint: register_int_gauge_with_registry!(
37                "last_certified_checkpoint",
38                "Last certified checkpoint",
39                registry
40            )
41            .unwrap(),
42            last_constructed_checkpoint: register_int_gauge_with_registry!(
43                "last_constructed_checkpoint",
44                "Last constructed checkpoint",
45                registry
46            )
47            .unwrap(),
48            last_created_checkpoint_age: register_histogram_with_registry!(
49                "last_created_checkpoint_age",
50                "Age of the last created checkpoint",
51                iota_metrics::LATENCY_SEC_BUCKETS.to_vec(),
52                registry
53            ).unwrap(),
54            last_certified_checkpoint_age: register_histogram_with_registry!(
55                "last_certified_checkpoint_age",
56                "Age of the last certified checkpoint",
57                iota_metrics::LATENCY_SEC_BUCKETS.to_vec(),
58                registry
59            ).unwrap(),
60            checkpoint_errors: register_int_counter_with_registry!(
61                "checkpoint_errors",
62                "Checkpoints errors count",
63                registry
64            )
65            .unwrap(),
66            transactions_included_in_checkpoint: register_int_counter_with_registry!(
67                "transactions_included_in_checkpoint",
68                "Transactions included in a checkpoint",
69                registry
70            )
71            .unwrap(),
72            checkpoint_roots_count: register_int_counter_with_registry!(
73                "checkpoint_roots_count",
74                "Number of checkpoint roots received from consensus",
75                registry
76            )
77            .unwrap(),
78            checkpoint_participation: register_int_counter_vec_with_registry!(
79                "checkpoint_participation",
80                "Participation in checkpoint certification by validator",
81                &["signer"],
82                registry
83            )
84            .unwrap(),
85            last_received_checkpoint_signatures: register_int_gauge_vec_with_registry!(
86                "last_received_checkpoint_signatures",
87                "Last received checkpoint signatures by validator",
88                &["signer"],
89                registry
90            )
91            .unwrap(),
92            last_sent_checkpoint_signature: register_int_gauge_with_registry!(
93                "last_sent_checkpoint_signature",
94                "Last checkpoint signature sent by myself",
95                registry
96            )
97            .unwrap(),
98            last_skipped_checkpoint_signature_submission: register_int_gauge_with_registry!(
99                "last_skipped_checkpoint_signature_submission",
100                "Last checkpoint signature that this validator skipped submitting because it was already certified.",
101                registry
102            )
103            .unwrap(),
104            last_ignored_checkpoint_signature_received: register_int_gauge_with_registry!(
105                "last_ignored_checkpoint_signature_received",
106                "Last received checkpoint signature that this validator ignored because it was already certified.",
107                registry
108            )
109            .unwrap(),
110            highest_accumulated_epoch: register_int_gauge_with_registry!(
111                "highest_accumulated_epoch",
112                "Highest accumulated epoch",
113                registry
114            )
115            .unwrap(),
116            checkpoint_creation_latency: register_histogram_with_registry!(
117                "checkpoint_creation_latency",
118                "Latency from consensus commit timestamp to local checkpoint creation in milliseconds",
119                iota_metrics::LATENCY_SEC_BUCKETS.to_vec(),
120                registry,
121            ).unwrap(),
122            remote_checkpoint_forks: register_int_counter_with_registry!(
123                "remote_checkpoint_forks",
124                "Number of remote checkpoints that forked from local checkpoints",
125                registry
126            )
127            .unwrap(),
128            split_brain_checkpoint_forks: register_int_counter_with_registry!(
129                "split_brain_checkpoint_forks",
130                "Number of checkpoints that have resulted in a split brain",
131                registry
132            )
133            .unwrap(),
134        };
135        Arc::new(this)
136    }
137
138    pub fn new_for_tests() -> Arc<Self> {
139        Self::new(&Registry::new())
140    }
141}