From 4768674cd4e5a09bb249ff6e9ce43a7c26f2f7e2 Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Mon, 23 Dec 2024 12:06:16 +0530 Subject: [PATCH] feat(metrics): count the number of relayed circuit connections --- ant-networking/src/event/swarm.rs | 12 ++++++++++++ ant-networking/src/metrics/mod.rs | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/ant-networking/src/event/swarm.rs b/ant-networking/src/event/swarm.rs index b37165bd50..47ff53d187 100644 --- a/ant-networking/src/event/swarm.rs +++ b/ant-networking/src/event/swarm.rs @@ -105,6 +105,18 @@ impl SwarmDriver { libp2p::relay::Event::ReservationTimedOut { src_peer_id } => { self.connected_relay_clients.remove(&src_peer_id); } + libp2p::relay::Event::CircuitReqAccepted { .. } => { + #[cfg(feature = "open-metrics")] + if let Some(metrics_recorder) = &self.metrics_recorder { + metrics_recorder.open_relayed_circuit_connections.inc(); + } + } + libp2p::relay::Event::CircuitClosed { .. } => { + #[cfg(feature = "open-metrics")] + if let Some(metrics_recorder) = &self.metrics_recorder { + metrics_recorder.open_relayed_circuit_connections.dec(); + } + } _ => {} } } diff --git a/ant-networking/src/metrics/mod.rs b/ant-networking/src/metrics/mod.rs index ef9f636bcb..9214e851e0 100644 --- a/ant-networking/src/metrics/mod.rs +++ b/ant-networking/src/metrics/mod.rs @@ -42,6 +42,7 @@ pub(crate) struct NetworkMetricsRecorder { pub(crate) connected_peers: Gauge, pub(crate) estimated_network_size: Gauge, pub(crate) open_connections: Gauge, + pub(crate) open_relayed_circuit_connections: Gauge, pub(crate) peers_in_routing_table: Gauge, pub(crate) records_stored: Gauge, @@ -98,6 +99,12 @@ impl NetworkMetricsRecorder { "The estimated number of nodes in the network calculated by the peers in our RT", estimated_network_size.clone(), ); + let open_relayed_circuit_connections = Gauge::default(); + sub_registry.register( + "open_relayed_circuit_connections", + "The number of active circuit connections that we are relaying between peers", + open_relayed_circuit_connections.clone(), + ); let open_connections = Gauge::default(); sub_registry.register( "open_connections", @@ -214,6 +221,7 @@ impl NetworkMetricsRecorder { estimated_network_size, connected_peers, open_connections, + open_relayed_circuit_connections, peers_in_routing_table, relevant_records, max_records,