cfxcore/pos/consensus/
counters.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8use diem_metrics::{
9    register_histogram, register_histogram_vec, register_int_counter,
10    register_int_counter_vec, register_int_gauge, DurationHistogram, Histogram,
11    HistogramVec, IntCounter, IntCounterVec, IntGauge,
12};
13use once_cell::sync::Lazy;
14
15//////////////////////
16// HEALTH COUNTERS
17//////////////////////
18
19/// Monitor counters, used by monitor! macro
20pub static OP_COUNTERS: Lazy<diem_metrics::OpMetrics> =
21    Lazy::new(|| diem_metrics::OpMetrics::new_and_registered("consensus"));
22
23pub static ERROR_COUNT: Lazy<IntGauge> = Lazy::new(|| {
24    register_int_gauge!(
25        "diem_consensus_error_count",
26        "Total number of errors in main loop"
27    )
28    .unwrap()
29});
30
31/// This counter is set to the round of the highest committed block.
32pub static LAST_COMMITTED_ROUND: Lazy<IntGauge> = Lazy::new(|| {
33    register_int_gauge!(
34        "diem_consensus_last_committed_round",
35        "This counter is set to the round of the highest committed block."
36    )
37    .unwrap()
38});
39
40/// The counter corresponds to the version of the last committed ledger info.
41pub static LAST_COMMITTED_VERSION: Lazy<IntGauge> = Lazy::new(|| {
42    register_int_gauge!(
43        "diem_consensus_last_committed_version",
44        "The counter corresponds to the version of the last committed ledger info."
45    )
46    .unwrap()
47});
48
49/// Count of the committed blocks since last restart.
50pub static COMMITTED_BLOCKS_COUNT: Lazy<IntCounter> = Lazy::new(|| {
51    register_int_counter!(
52        "diem_consensus_committed_blocks_count",
53        "Count of the committed blocks since last restart."
54    )
55    .unwrap()
56});
57
58/// Count of the committed transactions since last restart.
59pub static COMMITTED_TXNS_COUNT: Lazy<IntCounterVec> = Lazy::new(|| {
60    register_int_counter_vec!(
61        "diem_consensus_committed_txns_count",
62        "Count of the transactions since last restart. state is success or failed",
63        &["state"]
64    )
65    .unwrap()
66});
67
68//////////////////////
69// PROPOSAL ELECTION
70//////////////////////
71
72/// Count of the block proposals sent by this validator since last restart
73/// (both primary and secondary)
74pub static PROPOSALS_COUNT: Lazy<IntCounter> = Lazy::new(|| {
75    register_int_counter!("diem_consensus_proposals_count", "Count of the block proposals sent by this validator since last restart (both primary and secondary)").unwrap()
76});
77
78/// Count the number of times a validator voted for a nil block since last
79/// restart.
80pub static VOTE_NIL_COUNT: Lazy<IntCounter> = Lazy::new(|| {
81    register_int_counter!(
82        "diem_consensus_vote_nil_count",
83        "Count the number of times a validator voted for a nil block since last restart."
84    )
85    .unwrap()
86});
87
88//////////////////////
89// RoundState COUNTERS
90//////////////////////
91/// This counter is set to the last round reported by the local round_state.
92pub static CURRENT_ROUND: Lazy<IntGauge> = Lazy::new(|| {
93    register_int_gauge!(
94        "diem_consensus_current_round",
95        "This counter is set to the last round reported by the local round_state."
96    )
97    .unwrap()
98});
99
100/// Count of the rounds that gathered QC since last restart.
101pub static QC_ROUNDS_COUNT: Lazy<IntCounter> = Lazy::new(|| {
102    register_int_counter!(
103        "diem_consensus_qc_rounds_count",
104        "Count of the rounds that gathered QC since last restart."
105    )
106    .unwrap()
107});
108
109/// Count of the timeout rounds since last restart (close to 0 in happy path).
110pub static TIMEOUT_ROUNDS_COUNT: Lazy<IntCounter> = Lazy::new(|| {
111    register_int_counter!(
112        "diem_consensus_timeout_rounds_count",
113        "Count of the timeout rounds since last restart (close to 0 in happy path)."
114    )
115    .unwrap()
116});
117
118/// Count the number of timeouts a node experienced since last restart (close to
119/// 0 in happy path). This count is different from `TIMEOUT_ROUNDS_COUNT`,
120/// because not every time a node has a timeout there is an ultimate decision to
121/// move to the next round (it might take multiple timeouts to get the timeout
122/// certificate).
123pub static TIMEOUT_COUNT: Lazy<IntCounter> = Lazy::new(|| {
124    register_int_counter!("diem_consensus_timeout_count", "Count the number of timeouts a node experienced since last restart (close to 0 in happy path).").unwrap()
125});
126
127/// The timeout of the current round.
128pub static ROUND_TIMEOUT_MS: Lazy<IntGauge> = Lazy::new(|| {
129    register_int_gauge!(
130        "diem_consensus_round_timeout_s",
131        "The timeout of the current round."
132    )
133    .unwrap()
134});
135
136////////////////////////
137// SYNC MANAGER COUNTERS
138////////////////////////
139/// Counts the number of times the sync info message has been set since last
140/// restart.
141pub static SYNC_INFO_MSGS_SENT_COUNT: Lazy<IntCounter> = Lazy::new(|| {
142    register_int_counter!(
143        "diem_consensus_sync_info_msg_sent_count",
144        "Counts the number of times the sync info message has been set since last restart."
145    )
146    .unwrap()
147});
148
149//////////////////////
150// RECONFIGURATION COUNTERS
151//////////////////////
152/// Current epoch num
153pub static EPOCH: Lazy<IntGauge> = Lazy::new(|| {
154    register_int_gauge!("diem_consensus_epoch", "Current epoch num").unwrap()
155});
156
157/// The number of validators in the current epoch
158pub static CURRENT_EPOCH_VALIDATORS: Lazy<IntGauge> = Lazy::new(|| {
159    register_int_gauge!(
160        "diem_consensus_current_epoch_validators",
161        "The number of validators in the current epoch"
162    )
163    .unwrap()
164});
165
166//////////////////////
167// BLOCK STORE COUNTERS
168//////////////////////
169/// Counter for the number of blocks in the block tree (including the root).
170/// In a "happy path" with no collisions and timeouts, should be equal to 3 or
171/// 4.
172pub static NUM_BLOCKS_IN_TREE: Lazy<IntGauge> = Lazy::new(|| {
173    register_int_gauge!(
174        "diem_consensus_num_blocks_in_tree",
175        "Counter for the number of blocks in the block tree (including the root)."
176    )
177    .unwrap()
178});
179
180//////////////////////
181// PERFORMANCE COUNTERS
182//////////////////////
183// TODO Consider reintroducing this counter
184// pub static UNWRAPPED_PROPOSAL_SIZE_BYTES: Lazy<Histogram> = Lazy::new(|| {
185//     register_histogram!(
186//         "diem_consensus_unwrapped_proposal_size_bytes",
187//         "Histogram of proposal size after BCS but before wrapping with GRPC
188// and diem net."     )
189//     .unwrap()
190// });
191
192/// Histogram for the number of txns per (committed) blocks.
193pub static NUM_TXNS_PER_BLOCK: Lazy<Histogram> = Lazy::new(|| {
194    register_histogram!(
195        "diem_consensus_num_txns_per_block",
196        "Histogram for the number of txns per (committed) blocks."
197    )
198    .unwrap()
199});
200
201pub static BLOCK_TRACING: Lazy<HistogramVec> = Lazy::new(|| {
202    register_histogram_vec!(
203        "diem_consensus_block_tracing",
204        "Histogram for different stages of a block",
205        &["stage"]
206    )
207    .unwrap()
208});
209
210/// Histogram of the time it requires to wait before inserting blocks into block
211/// store. Measured as the block's timestamp minus local timestamp.
212pub static WAIT_DURATION_S: Lazy<DurationHistogram> = Lazy::new(|| {
213    DurationHistogram::new(register_histogram!("diem_consensus_wait_duration_s", "Histogram of the time it requires to wait before inserting blocks into block store. Measured as the block's timestamp minus the local timestamp.").unwrap())
214});
215
216///////////////////
217// CHANNEL COUNTERS
218///////////////////
219/// Count of the pending messages sent to itself in the channel
220#[allow(unused)]
221pub static PENDING_SELF_MESSAGES: Lazy<IntGauge> = Lazy::new(|| {
222    register_int_gauge!(
223        "diem_consensus_pending_self_messages",
224        "Count of the pending messages sent to itself in the channel"
225    )
226    .unwrap()
227});
228
229/// Count of the pending outbound round timeouts
230pub static PENDING_ROUND_TIMEOUTS: Lazy<IntGauge> = Lazy::new(|| {
231    register_int_gauge!(
232        "diem_consensus_pending_round_timeouts",
233        "Count of the pending outbound round timeouts"
234    )
235    .unwrap()
236});
237
238pub static PENDING_PROPOSAL_TIMEOUTS: Lazy<IntGauge> = Lazy::new(|| {
239    register_int_gauge!(
240        "diem_consensus_pending_proposal_timeouts",
241        "Count of the pending outbound proposal timeouts"
242    )
243    .unwrap()
244});
245pub static PENDING_NEW_ROUND_TIMEOUTS: Lazy<IntGauge> = Lazy::new(|| {
246    register_int_gauge!(
247        "diem_consensus_pending_new_round_timeouts",
248        "Count of the pending outbound new round timeouts"
249    )
250    .unwrap()
251});
252
253/// Counter of pending network events to Consensus
254#[allow(unused)]
255pub static PENDING_CONSENSUS_NETWORK_EVENTS: Lazy<IntCounterVec> = Lazy::new(
256    || {
257        register_int_counter_vec!(
258        "diem_consensus_pending_network_events",
259        "Counters(queued,dequeued,dropped) related to pending network notifications to Consensus",
260        &["state"]
261    )
262    .unwrap()
263    },
264);
265
266/// Counters(queued,dequeued,dropped) related to consensus channel
267pub static CONSENSUS_CHANNEL_MSGS: Lazy<IntCounterVec> = Lazy::new(|| {
268    register_int_counter_vec!(
269        "diem_consensus_channel_msgs_count",
270        "Counters(queued,dequeued,dropped) related to consensus channel",
271        &["state"]
272    )
273    .unwrap()
274});
275
276/// Counters(queued,dequeued,dropped) related to block retrieval channel
277pub static BLOCK_RETRIEVAL_CHANNEL_MSGS: Lazy<IntCounterVec> =
278    Lazy::new(|| {
279        register_int_counter_vec!(
280        "diem_consensus_block_retrieval_channel_msgs_count",
281        "Counters(queued,dequeued,dropped) related to block retrieval channel",
282        &["state"]
283    )
284        .unwrap()
285    });