1use 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 pub network_peer_connected: IntGaugeVec,
12 pub network_peers: IntGauge,
14 pub network_peer_disconnects: IntCounterVec,
16 pub socket_receive_buffer_size: IntGauge,
18 pub socket_send_buffer_size: IntGauge,
20
21 pub network_peer_rtt: IntGaugeVec,
24 pub network_peer_lost_packets: IntGaugeVec,
26 pub network_peer_lost_bytes: IntGaugeVec,
28 pub network_peer_sent_packets: IntGaugeVec,
30 pub network_peer_congestion_events: IntGaugeVec,
32 pub network_peer_congestion_window: IntGaugeVec,
34
35 pub network_peer_max_data: IntGaugeVec,
38 pub network_peer_closed_connections: IntGaugeVec,
40 pub network_peer_data_blocked: IntGaugeVec,
42
43 pub network_peer_udp_datagrams: IntGaugeVec,
46 pub network_peer_udp_bytes: IntGaugeVec,
48 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 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 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 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}