sui_core/validator_client_monitor/
metrics.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use mysten_metrics::{COUNT_BUCKETS, LATENCY_SEC_BUCKETS};
5use prometheus::{
6    GaugeVec, HistogramVec, IntCounterVec, Registry, register_gauge_vec_with_registry,
7    register_histogram_vec_with_registry, register_int_counter_vec_with_registry,
8};
9
10#[derive(Clone)]
11pub struct ValidatorClientMetrics {
12    /// Latency of operations per validator
13    pub observed_latency: HistogramVec,
14
15    /// Success count per validator and operation type
16    pub operation_success: IntCounterVec,
17
18    /// Failure count per validator and operation type
19    pub operation_failure: IntCounterVec,
20
21    /// Current performance per validator. The performance is the average latency of the validator
22    /// weighted by the reliability of the validator.
23    pub performance: GaugeVec,
24
25    /// Number of low latency validators that got shuffled.
26    pub shuffled_validators: HistogramVec,
27}
28
29impl ValidatorClientMetrics {
30    pub fn new(registry: &Registry) -> Self {
31        Self {
32            observed_latency: register_histogram_vec_with_registry!(
33                "validator_client_observed_latency",
34                "Client-observed latency of operations per validator",
35                &["validator", "operation_type", "ping"],
36                LATENCY_SEC_BUCKETS.to_vec(),
37                registry,
38            )
39            .unwrap(),
40
41            operation_success: register_int_counter_vec_with_registry!(
42                "validator_client_operation_success_total",
43                "Total successful operations observed by client per validator",
44                &["validator", "operation_type", "ping"],
45                registry,
46            )
47            .unwrap(),
48
49            operation_failure: register_int_counter_vec_with_registry!(
50                "validator_client_operation_failure_total",
51                "Total failed operations observed by client per validator",
52                &["validator", "operation_type", "ping"],
53                registry,
54            )
55            .unwrap(),
56
57            performance: register_gauge_vec_with_registry!(
58                "validator_client_observed_performance",
59                "Current client-observed performance per validator. The performance is the average latency of the validator
60                weighted by the reliability of the validator.",
61                &["validator", "tx_type"],
62                registry,
63            )
64            .unwrap(),
65
66            shuffled_validators: register_histogram_vec_with_registry!(
67                "validator_client_shuffled_validators",
68                "Number of low latency validators that got shuffled",
69                &["tx_type"],
70                COUNT_BUCKETS.to_vec(),
71                registry,
72            )
73            .unwrap(),
74        }
75    }
76
77    pub fn new_for_tests() -> Self {
78        let registry = Registry::new();
79        Self::new(&registry)
80    }
81}