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, SUBSECOND_LATENCY_SEC_BUCKETS};
5use prometheus::{
6    GaugeVec, Histogram, HistogramVec, IntCounterVec, Registry, register_gauge_vec_with_registry,
7    register_histogram_vec_with_registry, register_histogram_with_registry,
8    register_int_counter_vec_with_registry,
9};
10
11#[derive(Clone)]
12pub struct ValidatorClientMetrics {
13    /// Latency of operations per validator
14    pub observed_latency: HistogramVec,
15
16    /// Success count per validator and operation type
17    pub operation_success: IntCounterVec,
18
19    /// Failure count per validator and operation type
20    pub operation_failure: IntCounterVec,
21
22    /// Current performance per validator. The performance is the average latency of the validator
23    /// weighted by the reliability of the validator.
24    pub performance: GaugeVec,
25
26    /// Number of low latency validators that got shuffled.
27    pub shuffled_validators: Histogram,
28}
29
30impl ValidatorClientMetrics {
31    pub fn new(registry: &Registry) -> Self {
32        Self {
33            observed_latency: register_histogram_vec_with_registry!(
34                "validator_client_observed_latency",
35                "Client-observed latency of operations per validator",
36                &["validator", "operation_type", "ping"],
37                SUBSECOND_LATENCY_SEC_BUCKETS.to_vec(),
38                registry,
39            )
40            .unwrap(),
41
42            operation_success: register_int_counter_vec_with_registry!(
43                "validator_client_operation_success_total",
44                "Total successful operations observed by client per validator",
45                &["validator", "operation_type", "ping"],
46                registry,
47            )
48            .unwrap(),
49
50            operation_failure: register_int_counter_vec_with_registry!(
51                "validator_client_operation_failure_total",
52                "Total failed operations observed by client per validator",
53                &["validator", "operation_type", "ping"],
54                registry,
55            )
56            .unwrap(),
57
58            performance: register_gauge_vec_with_registry!(
59                "validator_client_observed_performance",
60                "Current client-observed performance per validator. The performance is the average latency of the validator
61                weighted by the reliability of the validator.",
62                &["validator"],
63                registry,
64            )
65            .unwrap(),
66
67            shuffled_validators: register_histogram_with_registry!(
68                "validator_client_shuffled_validators",
69                "Number of low latency validators that got shuffled",
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}