Skip to content

Commit

Permalink
feat(metrics): expose open_connections separately
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin authored and joshuef committed Jun 18, 2024
1 parent 5566539 commit 6f346b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 12 additions & 3 deletions sn_networking/src/event/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down Expand Up @@ -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:?}");
}
Expand Down
10 changes: 9 additions & 1 deletion sn_networking/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -107,6 +114,7 @@ impl NetworkMetrics {
records_stored,
estimated_network_size,
connected_peers,
open_connections,
peers_in_routing_table,
store_cost,
#[cfg(feature = "upnp")]
Expand Down

0 comments on commit 6f346b3

Please sign in to comment.