From da04ce3d357a5eeccd0042330a86f623b7565876 Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Mon, 17 Jun 2024 14:25:55 +0530 Subject: [PATCH] feat(metrics): expose open_connections separately --- sn_networking/src/event/swarm.rs | 15 ++++++++++++--- sn_networking/src/metrics/mod.rs | 10 +++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sn_networking/src/event/swarm.rs b/sn_networking/src/event/swarm.rs index a5048e8d08..4f7c9bc462 100644 --- a/sn_networking/src/event/swarm.rs +++ b/sn_networking/src/event/swarm.rs @@ -384,8 +384,11 @@ impl SwarmDriver { #[cfg(feature = "open-metrics")] if let Some(metrics) = &self.network_metrics { metrics - .connected_peers + .open_connections .set(self.live_connected_peers.len() as i64); + metrics + .connected_peers + .set(self.swarm.connected_peers().count() as i64); } if endpoint.is_dialer() { @@ -405,8 +408,11 @@ impl SwarmDriver { #[cfg(feature = "open-metrics")] if let Some(metrics) = &self.network_metrics { metrics - .connected_peers + .open_connections .set(self.live_connected_peers.len() as i64); + metrics + .connected_peers + .set(self.swarm.connected_peers().count() as i64); } } SwarmEvent::OutgoingConnectionError { @@ -700,8 +706,11 @@ impl SwarmDriver { #[cfg(feature = "open-metrics")] if let Some(metrics) = &self.network_metrics { metrics - .connected_peers + .open_connections .set(self.live_connected_peers.len() as i64); + metrics + .connected_peers + .set(self.swarm.connected_peers().count() as i64); } trace!("Removed outdated connection {connection_id:?} to {peer_id:?} with result: {result:?}"); } diff --git a/sn_networking/src/metrics/mod.rs b/sn_networking/src/metrics/mod.rs index c4e888a11f..cdb351407e 100644 --- a/sn_networking/src/metrics/mod.rs +++ b/sn_networking/src/metrics/mod.rs @@ -28,8 +28,9 @@ pub(crate) struct NetworkMetrics { libp2p_metrics: Libp2pMetrics, // metrics from sn_networking - pub(crate) estimated_network_size: Gauge, pub(crate) connected_peers: Gauge, + pub(crate) estimated_network_size: Gauge, + pub(crate) open_connections: Gauge, pub(crate) peers_in_routing_table: Gauge, pub(crate) records_stored: Gauge, pub(crate) store_cost: Gauge, @@ -66,6 +67,12 @@ impl NetworkMetrics { "The estimated number of nodes in the network calculated by the peers in our RT", estimated_network_size.clone(), ); + let open_connections = Gauge::default(); + sub_registry.register( + "open_connections", + "The number of active connections to other peers", + open_connections.clone(), + ); let peers_in_routing_table = Gauge::default(); sub_registry.register( "peers_in_routing_table", @@ -107,6 +114,7 @@ impl NetworkMetrics { records_stored, estimated_network_size, connected_peers, + open_connections, peers_in_routing_table, store_cost, #[cfg(feature = "upnp")]