From 4f449f32e979214ffd019cc45ab5dcd17b2ad93b Mon Sep 17 00:00:00 2001 From: Abhijith Ganesh <67182544+AbhijithGanesh@users.noreply.github.com> Date: Thu, 11 Aug 2022 21:55:34 +0530 Subject: [PATCH] Addition of protocol relevant information Signed-off-by: Abhijith Ganesh <67182544+AbhijithGanesh@users.noreply.github.com> --- misc/metrics/src/logging.rs | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 misc/metrics/src/logging.rs diff --git a/misc/metrics/src/logging.rs b/misc/metrics/src/logging.rs new file mode 100644 index 00000000000..0dbaee54be7 --- /dev/null +++ b/misc/metrics/src/logging.rs @@ -0,0 +1,46 @@ +use libp2p::multiaddr::Protocol; +use libp2p::swarm::{Swarm, SwarmEvent}; +use libp2p::{Multiaddr, PeerId}; +use prometheus_client::metrics::gauge::Gauge; + +struct ProtocolStack(String); + +impl From for ProtocolStack { + fn from(address: Multiaddr) -> Self { + Self( + address + .into_iter() + .map(|p| match p { + Protocol::Dccp(_) => "dccp", + Protocol::Dns(_) => "dns", + Protocol::Dns4(_) => "dns4", + Protocol::Dns6(_) => "dns6", + Protocol::Dnsaddr(_) => "dnsaddr", + Protocol::Http => "http", + Protocol::Https => "https", + Protocol::Ip4(_) => "ip4", + Protocol::Ip6(_) => "ip6", + Protocol::P2pWebRtcDirect => "p2pwebrtcdirect", + Protocol::P2pWebRtcStar => "p2pwebrtcstar", + Protocol::P2pWebSocketStar => "p2pwebsocketstar", + Protocol::Memory(_) => "memory", + Protocol::Onion(_, _) => "onion", + Protocol::Onion3(_) => "onion3", + Protocol::P2p(_) => "p2p", + Protocol::P2pCircuit => "p2pcircuit", + Protocol::Quic => "quic", + Protocol::Sctp(_) => "sctp", + Protocol::Tcp(_) => "tcp", + Protocol::Tls => "tls", + Protocol::Udp(_) => "udp", + Protocol::Udt => "udt", + Protocol::Unix(_) => "unix", + Protocol::Utp => "utp", + Protocol::Ws(_) => "ws", + Protocol::Wss(_) => "wss", + }) + .intersperse("/") + .collect(), + ) + } +}