sui_core/checkpoints/
metrics.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use mysten_metrics::histogram::Histogram as MystenHistogram;
5use prometheus::{
6    Histogram, IntCounter, IntCounterVec, IntGauge, IntGaugeVec, Registry,
7    register_histogram_with_registry, register_int_counter_vec_with_registry,
8    register_int_counter_with_registry, register_int_gauge_vec_with_registry,
9    register_int_gauge_with_registry,
10};
11use std::sync::Arc;
12
13pub struct CheckpointMetrics {
14    pub last_certified_checkpoint: IntGauge,
15    pub last_constructed_checkpoint: IntGauge,
16    pub checkpoint_errors: IntCounter,
17    pub transactions_included_in_checkpoint: IntCounter,
18    pub checkpoint_roots_count: IntCounter,
19    pub checkpoint_participation: IntCounterVec,
20    pub last_received_checkpoint_signatures: IntGaugeVec,
21    pub last_sent_checkpoint_signature: IntGauge,
22    pub last_skipped_checkpoint_signature_submission: IntGauge,
23    pub last_ignored_checkpoint_signature_received: IntGauge,
24    pub highest_accumulated_epoch: IntGauge,
25    pub checkpoint_creation_latency: Histogram,
26    // TODO: delete once users are migrated to non-Mysten histogram.
27    pub checkpoint_creation_latency_ms: MystenHistogram,
28    pub remote_checkpoint_forks: IntCounter,
29    pub split_brain_checkpoint_forks: IntCounter,
30    pub checkpoint_fork_crash_mode: IntGaugeVec,
31    pub transaction_fork_crash_mode: IntGaugeVec,
32    pub last_created_checkpoint_age: Histogram,
33    // TODO: delete once users are migrated to non-Mysten histogram.
34    pub last_created_checkpoint_age_ms: MystenHistogram,
35    pub last_certified_checkpoint_age: Histogram,
36    // TODO: delete once users are migrated to non-Mysten histogram.
37    pub last_certified_checkpoint_age_ms: MystenHistogram,
38}
39
40impl CheckpointMetrics {
41    pub fn new(registry: &Registry) -> Arc<Self> {
42        let this = Self {
43            last_certified_checkpoint: register_int_gauge_with_registry!(
44                "last_certified_checkpoint",
45                "Last certified checkpoint",
46                registry
47            )
48            .unwrap(),
49            last_constructed_checkpoint: register_int_gauge_with_registry!(
50                "last_constructed_checkpoint",
51                "Last constructed checkpoint",
52                registry
53            )
54            .unwrap(),
55            last_created_checkpoint_age: register_histogram_with_registry!(
56                "last_created_checkpoint_age",
57                "Age of the last created checkpoint",
58                mysten_metrics::LATENCY_SEC_BUCKETS.to_vec(),
59                registry
60            ).unwrap(),
61            last_created_checkpoint_age_ms: MystenHistogram::new_in_registry(
62                "last_created_checkpoint_age_ms",
63                "Age of the last created checkpoint",
64                registry
65            ),
66            last_certified_checkpoint_age: register_histogram_with_registry!(
67                "last_certified_checkpoint_age",
68                "Age of the last certified checkpoint",
69                mysten_metrics::LATENCY_SEC_BUCKETS.to_vec(),
70                registry
71            ).unwrap(),
72            last_certified_checkpoint_age_ms: MystenHistogram::new_in_registry(
73                "last_certified_checkpoint_age_ms",
74                "Age of the last certified checkpoint",
75                registry
76            ),
77            checkpoint_errors: register_int_counter_with_registry!(
78                "checkpoint_errors",
79                "Checkpoints errors count",
80                registry
81            )
82            .unwrap(),
83            transactions_included_in_checkpoint: register_int_counter_with_registry!(
84                "transactions_included_in_checkpoint",
85                "Transactions included in a checkpoint",
86                registry
87            )
88            .unwrap(),
89            checkpoint_roots_count: register_int_counter_with_registry!(
90                "checkpoint_roots_count",
91                "Number of checkpoint roots received from consensus",
92                registry
93            )
94            .unwrap(),
95            checkpoint_participation: register_int_counter_vec_with_registry!(
96                "checkpoint_participation",
97                "Participation in checkpoint certification by validator",
98                &["signer"],
99                registry
100            )
101            .unwrap(),
102            last_received_checkpoint_signatures: register_int_gauge_vec_with_registry!(
103                "last_received_checkpoint_signatures",
104                "Last received checkpoint signatures by validator",
105                &["signer"],
106                registry
107            )
108            .unwrap(),
109            last_sent_checkpoint_signature: register_int_gauge_with_registry!(
110                "last_sent_checkpoint_signature",
111                "Last checkpoint signature sent by myself",
112                registry
113            )
114            .unwrap(),
115            last_skipped_checkpoint_signature_submission: register_int_gauge_with_registry!(
116                "last_skipped_checkpoint_signature_submission",
117                "Last checkpoint signature that this validator skipped submitting because it was already certfied.",
118                registry
119            )
120            .unwrap(),
121            last_ignored_checkpoint_signature_received: register_int_gauge_with_registry!(
122                "last_ignored_checkpoint_signature_received",
123                "Last received checkpoint signature that this validator ignored because it was already certfied.",
124                registry
125            )
126            .unwrap(),
127            highest_accumulated_epoch: register_int_gauge_with_registry!(
128                "highest_accumulated_epoch",
129                "Highest accumulated epoch",
130                registry
131            )
132            .unwrap(),
133            checkpoint_creation_latency: register_histogram_with_registry!(
134                "checkpoint_creation_latency",
135                "Latency from consensus commit timstamp to local checkpoint creation in milliseconds",
136                mysten_metrics::LATENCY_SEC_BUCKETS.to_vec(),
137                registry,
138            ).unwrap(),
139            checkpoint_creation_latency_ms: MystenHistogram::new_in_registry(
140                "checkpoint_creation_latency_ms",
141                "Latency from consensus commit timstamp to local checkpoint creation in milliseconds",
142                registry,
143            ),
144            remote_checkpoint_forks: register_int_counter_with_registry!(
145                "remote_checkpoint_forks",
146                "Number of remote checkpoints that forked from local checkpoints",
147                registry
148            )
149            .unwrap(),
150            split_brain_checkpoint_forks: register_int_counter_with_registry!(
151                "split_brain_checkpoint_forks",
152                "Number of checkpoints that have resulted in a split brain",
153                registry
154            )
155            .unwrap(),
156            checkpoint_fork_crash_mode: register_int_gauge_vec_with_registry!(
157                "checkpoint_fork_crash_mode",
158                "Indicates node is in crash mode due to checkpoint fork",
159                &["checkpoint_seq", "checkpoint_digest_prefix", "detected_at"],
160                registry
161            )
162            .unwrap(),
163            transaction_fork_crash_mode: register_int_gauge_vec_with_registry!(
164                "transaction_fork_crash_mode",
165                "Indicates node is in crash mode due to transaction fork",
166                &["tx_digest_prefix", "expected_effects_prefix", "actual_effects_prefix", "detected_at"],
167                registry
168            )
169            .unwrap(),
170        };
171        Arc::new(this)
172    }
173
174    pub fn new_for_tests() -> Arc<Self> {
175        Self::new(&Registry::new())
176    }
177}