From e0aadc556d45aaf3ed252424bd2e1d5ac4edff93 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Thu, 9 Sep 2021 15:07:48 +0200 Subject: [PATCH] misc/metrics/src/swarm: Expose role on connections_closed Expose whether closed connection was a Dialer or Listener. --- misc/metrics/src/swarm.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/misc/metrics/src/swarm.rs b/misc/metrics/src/swarm.rs index 630479a2f9c..a0c9c72fedf 100644 --- a/misc/metrics/src/swarm.rs +++ b/misc/metrics/src/swarm.rs @@ -27,8 +27,8 @@ pub struct Metrics { connections_incoming: Counter, connections_incoming_error: Family, - connections_established: Family, - connections_closed: Counter, + connections_established: Family, + connections_closed: Family, new_listen_addr: Counter, expired_listen_addr: Counter, @@ -115,7 +115,7 @@ impl Metrics { Box::new(connections_established.clone()), ); - let connections_closed = Counter::default(); + let connections_closed = Family::default(); sub_registry.register( "connections_closed", "Number of connections closed", @@ -147,13 +147,18 @@ impl super::Recorder { self.swarm .connections_established - .get_or_create(&ConnectionEstablishedLabeles { + .get_or_create(&ConnectionEstablishedLabels { role: endpoint.into(), }) .inc(); } - libp2p_swarm::SwarmEvent::ConnectionClosed { .. } => { - self.swarm.connections_closed.inc(); + libp2p_swarm::SwarmEvent::ConnectionClosed { endpoint, .. } => { + self.swarm + .connections_closed + .get_or_create(&ConnectionClosedLabels { + role: endpoint.into(), + }) + .inc(); } libp2p_swarm::SwarmEvent::IncomingConnection { .. } => { self.swarm.connections_incoming.inc(); @@ -201,7 +206,12 @@ impl super::Recorder