Skip to content

Commit

Permalink
feat(metrics): count the number of relayed circuit connections
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin committed Dec 23, 2024
1 parent 4e671d7 commit 4768674
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ant-networking/src/event/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
_ => {}
}
}
Expand Down
8 changes: 8 additions & 0 deletions ant-networking/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4768674

Please sign in to comment.