| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] |
| |
|
| | mod bandwidth; |
| | #[cfg(feature = "dcutr")] |
| | mod dcutr; |
| | #[cfg(feature = "gossipsub")] |
| | mod gossipsub; |
| | #[cfg(feature = "identify")] |
| | mod identify; |
| | #[cfg(feature = "kad")] |
| | mod kad; |
| | #[cfg(feature = "ping")] |
| | mod ping; |
| | mod protocol_stack; |
| | #[cfg(feature = "relay")] |
| | mod relay; |
| | mod swarm; |
| |
|
| | pub use bandwidth::Transport as BandwidthTransport; |
| | pub use prometheus_client::registry::Registry; |
| |
|
| | |
| | pub struct Metrics { |
| | #[cfg(feature = "dcutr")] |
| | dcutr: dcutr::Metrics, |
| | #[cfg(feature = "gossipsub")] |
| | gossipsub: gossipsub::Metrics, |
| | #[cfg(feature = "identify")] |
| | identify: identify::Metrics, |
| | #[cfg(feature = "kad")] |
| | kad: kad::Metrics, |
| | #[cfg(feature = "ping")] |
| | ping: ping::Metrics, |
| | #[cfg(feature = "relay")] |
| | relay: relay::Metrics, |
| | swarm: swarm::Metrics, |
| | } |
| |
|
| | impl Metrics { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | pub fn new(registry: &mut Registry) -> Self { |
| | let sub_registry = registry.sub_registry_with_prefix("libp2p"); |
| | Self { |
| | #[cfg(feature = "dcutr")] |
| | dcutr: dcutr::Metrics::new(sub_registry), |
| | #[cfg(feature = "gossipsub")] |
| | gossipsub: gossipsub::Metrics::new(sub_registry), |
| | #[cfg(feature = "identify")] |
| | identify: identify::Metrics::new(sub_registry), |
| | #[cfg(feature = "kad")] |
| | kad: kad::Metrics::new(sub_registry), |
| | #[cfg(feature = "ping")] |
| | ping: ping::Metrics::new(sub_registry), |
| | #[cfg(feature = "relay")] |
| | relay: relay::Metrics::new(sub_registry), |
| | swarm: swarm::Metrics::new(sub_registry), |
| | } |
| | } |
| | } |
| |
|
| | |
| | pub trait Recorder<Event> { |
| | |
| | fn record(&self, event: &Event); |
| | } |
| |
|
| | #[cfg(feature = "dcutr")] |
| | impl Recorder<libp2p_dcutr::Event> for Metrics { |
| | fn record(&self, event: &libp2p_dcutr::Event) { |
| | self.dcutr.record(event) |
| | } |
| | } |
| |
|
| | #[cfg(feature = "gossipsub")] |
| | impl Recorder<libp2p_gossipsub::Event> for Metrics { |
| | fn record(&self, event: &libp2p_gossipsub::Event) { |
| | self.gossipsub.record(event) |
| | } |
| | } |
| |
|
| | #[cfg(feature = "identify")] |
| | impl Recorder<libp2p_identify::Event> for Metrics { |
| | fn record(&self, event: &libp2p_identify::Event) { |
| | self.identify.record(event) |
| | } |
| | } |
| |
|
| | #[cfg(feature = "kad")] |
| | impl Recorder<libp2p_kad::Event> for Metrics { |
| | fn record(&self, event: &libp2p_kad::Event) { |
| | self.kad.record(event) |
| | } |
| | } |
| |
|
| | #[cfg(feature = "ping")] |
| | impl Recorder<libp2p_ping::Event> for Metrics { |
| | fn record(&self, event: &libp2p_ping::Event) { |
| | self.ping.record(event) |
| | } |
| | } |
| |
|
| | #[cfg(feature = "relay")] |
| | impl Recorder<libp2p_relay::Event> for Metrics { |
| | fn record(&self, event: &libp2p_relay::Event) { |
| | self.relay.record(event) |
| | } |
| | } |
| |
|
| | impl<TBvEv> Recorder<libp2p_swarm::SwarmEvent<TBvEv>> for Metrics { |
| | fn record(&self, event: &libp2p_swarm::SwarmEvent<TBvEv>) { |
| | self.swarm.record(event); |
| |
|
| | #[cfg(feature = "identify")] |
| | self.identify.record(event) |
| | } |
| | } |
| |
|