Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc/metrics/src/swarm: Expose role on connections_closed #2220

Merged
merged 1 commit into from
Sep 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions misc/metrics/src/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub struct Metrics {
connections_incoming: Counter,
connections_incoming_error: Family<IncomingConnectionErrorLabels, Counter>,

connections_established: Family<ConnectionEstablishedLabeles, Counter>,
connections_closed: Counter,
connections_established: Family<ConnectionEstablishedLabels, Counter>,
connections_closed: Family<ConnectionClosedLabels, Counter>,

new_listen_addr: Counter,
expired_listen_addr: Counter,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -147,13 +147,18 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
libp2p_swarm::SwarmEvent::ConnectionEstablished { endpoint, .. } => {
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();
Expand Down Expand Up @@ -201,7 +206,12 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
}

#[derive(Encode, Hash, Clone, Eq, PartialEq)]
struct ConnectionEstablishedLabeles {
struct ConnectionEstablishedLabels {
role: Role,
}

#[derive(Encode, Hash, Clone, Eq, PartialEq)]
struct ConnectionClosedLabels {
role: Role,
}

Expand Down