mysten_network/
quinn_metrics.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use prometheus::{
5    IntCounterVec, IntGauge, IntGaugeVec, Registry, register_int_counter_vec_with_registry,
6    register_int_gauge_vec_with_registry, register_int_gauge_with_registry,
7};
8
9pub struct QuinnConnectionMetrics {
10    /// The connection status of known peers. 0 if not connected, 1 if connected.
11    pub network_peer_connected: IntGaugeVec,
12    /// The number of connected peers
13    pub network_peers: IntGauge,
14    /// Number of disconnect events per peer.
15    pub network_peer_disconnects: IntCounterVec,
16    /// Receive buffer size of Anemo socket.
17    pub socket_receive_buffer_size: IntGauge,
18    /// Send buffer size of Anemo socket.
19    pub socket_send_buffer_size: IntGauge,
20
21    /// PathStats
22    /// The rtt for a peer connection in ms.
23    pub network_peer_rtt: IntGaugeVec,
24    /// The total number of lost packets for a peer connection.
25    pub network_peer_lost_packets: IntGaugeVec,
26    /// The total number of lost bytes for a peer connection.
27    pub network_peer_lost_bytes: IntGaugeVec,
28    /// The total number of packets sent for a peer connection.
29    pub network_peer_sent_packets: IntGaugeVec,
30    /// The total number of congestion events for a peer connection.
31    pub network_peer_congestion_events: IntGaugeVec,
32    /// The congestion window for a peer connection.
33    pub network_peer_congestion_window: IntGaugeVec,
34
35    /// FrameStats
36    /// The number of max data frames for a peer connection.
37    pub network_peer_max_data: IntGaugeVec,
38    /// The number of closed connections frames for a peer connection.
39    pub network_peer_closed_connections: IntGaugeVec,
40    /// The number of data blocked frames for a peer connection.
41    pub network_peer_data_blocked: IntGaugeVec,
42
43    /// UDPStats
44    /// The total number datagrams observed by the UDP peer connection.
45    pub network_peer_udp_datagrams: IntGaugeVec,
46    /// The total number bytes observed by the UDP peer connection.
47    pub network_peer_udp_bytes: IntGaugeVec,
48    /// The total number transmits observed by the UDP peer connection.
49    pub network_peer_udp_transmits: IntGaugeVec,
50}
51
52impl QuinnConnectionMetrics {
53    pub fn new(node: &'static str, registry: &Registry) -> Self {
54        Self {
55            network_peer_connected: register_int_gauge_vec_with_registry!(
56                format!("{node}_quinn_network_peer_connected"),
57                "The connection status of a peer. 0 if not connected, 1 if connected",
58                &["peer_id", "peer_label"],
59                registry
60            )
61            .unwrap(),
62            network_peers: register_int_gauge_with_registry!(
63                format!("{node}_quinn_network_peers"),
64                "The number of connected peers.",
65                registry
66            )
67            .unwrap(),
68            network_peer_disconnects: register_int_counter_vec_with_registry!(
69                format!("{node}_quinn_network_peer_disconnects"),
70                "Number of disconnect events per peer.",
71                &["peer_id", "peer_label", "reason"],
72                registry
73            )
74            .unwrap(),
75            socket_receive_buffer_size: register_int_gauge_with_registry!(
76                format!("{node}_quinn_socket_receive_buffer_size"),
77                "Receive buffer size of Anemo socket.",
78                registry
79            )
80            .unwrap(),
81            socket_send_buffer_size: register_int_gauge_with_registry!(
82                format!("{node}_quinn_socket_send_buffer_size"),
83                "Send buffer size of Anemo socket.",
84                registry
85            )
86            .unwrap(),
87
88            // PathStats
89            network_peer_rtt: register_int_gauge_vec_with_registry!(
90                format!("{node}_quinn_network_peer_rtt"),
91                "The rtt for a peer connection in ms.",
92                &["peer_id", "peer_label"],
93                registry
94            )
95            .unwrap(),
96            network_peer_lost_packets: register_int_gauge_vec_with_registry!(
97                format!("{node}_quinn_network_peer_lost_packets"),
98                "The total number of lost packets for a peer connection.",
99                &["peer_id", "peer_label"],
100                registry
101            )
102            .unwrap(),
103            network_peer_lost_bytes: register_int_gauge_vec_with_registry!(
104                format!("{node}_quinn_network_peer_lost_bytes"),
105                "The total number of lost bytes for a peer connection.",
106                &["peer_id", "peer_label"],
107                registry
108            )
109            .unwrap(),
110            network_peer_sent_packets: register_int_gauge_vec_with_registry!(
111                format!("{node}_quinn_network_peer_sent_packets"),
112                "The total number of sent packets for a peer connection.",
113                &["peer_id", "peer_label"],
114                registry
115            )
116            .unwrap(),
117            network_peer_congestion_events: register_int_gauge_vec_with_registry!(
118                format!("{node}_quinn_network_peer_congestion_events"),
119                "The total number of congestion events for a peer connection.",
120                &["peer_id", "peer_label"],
121                registry
122            )
123            .unwrap(),
124            network_peer_congestion_window: register_int_gauge_vec_with_registry!(
125                format!("{node}_quinn_network_peer_congestion_window"),
126                "The congestion window for a peer connection.",
127                &["peer_id", "peer_label"],
128                registry
129            )
130            .unwrap(),
131
132            // FrameStats
133            network_peer_closed_connections: register_int_gauge_vec_with_registry!(
134                format!("{node}_quinn_network_peer_closed_connections"),
135                "The number of closed connections for a peer connection.",
136                &["peer_id", "peer_label", "direction"],
137                registry
138            )
139            .unwrap(),
140            network_peer_max_data: register_int_gauge_vec_with_registry!(
141                format!("{node}_quinn_network_peer_max_data"),
142                "The number of max data frames for a peer connection.",
143                &["peer_id", "peer_label", "direction"],
144                registry
145            )
146            .unwrap(),
147            network_peer_data_blocked: register_int_gauge_vec_with_registry!(
148                format!("{node}_quinn_network_peer_data_blocked"),
149                "The number of data blocked frames for a peer connection.",
150                &["peer_id", "peer_label", "direction"],
151                registry
152            )
153            .unwrap(),
154
155            // UDPStats
156            network_peer_udp_datagrams: register_int_gauge_vec_with_registry!(
157                format!("{node}_quinn_network_peer_udp_datagrams"),
158                "The total number datagrams observed by the UDP peer connection.",
159                &["peer_id", "peer_label", "direction"],
160                registry
161            )
162            .unwrap(),
163            network_peer_udp_bytes: register_int_gauge_vec_with_registry!(
164                format!("{node}_quinn_network_peer_udp_bytes"),
165                "The total number bytes observed by the UDP peer connection.",
166                &["peer_id", "peer_label", "direction"],
167                registry
168            )
169            .unwrap(),
170            network_peer_udp_transmits: register_int_gauge_vec_with_registry!(
171                format!("{node}_quinn_network_peer_udp_transmits"),
172                "The total number transmits observed by the UDP peer connection.",
173                &["peer_id", "peer_label", "direction"],
174                registry
175            )
176            .unwrap(),
177        }
178    }
179}