| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | use prometheus_client::encoding::{EncodeLabelSet, EncodeLabelValue}; |
| | use prometheus_client::metrics::counter::Counter; |
| | use prometheus_client::metrics::family::Family; |
| | use prometheus_client::registry::Registry; |
| |
|
| | pub(crate) struct Metrics { |
| | events: Family<EventLabels, Counter>, |
| | } |
| |
|
| | impl Metrics { |
| | pub(crate) fn new(registry: &mut Registry) -> Self { |
| | let sub_registry = registry.sub_registry_with_prefix("dcutr"); |
| |
|
| | let events = Family::default(); |
| | sub_registry.register( |
| | "events", |
| | "Events emitted by the relay NetworkBehaviour", |
| | events.clone(), |
| | ); |
| |
|
| | Self { events } |
| | } |
| | } |
| |
|
| | #[derive(Debug, Clone, Hash, PartialEq, Eq, EncodeLabelSet)] |
| | struct EventLabels { |
| | event: EventType, |
| | } |
| |
|
| | #[derive(Debug, Clone, Hash, PartialEq, Eq, EncodeLabelValue)] |
| | enum EventType { |
| | DirectConnectionUpgradeSucceeded, |
| | DirectConnectionUpgradeFailed, |
| | } |
| |
|
| | impl From<&libp2p_dcutr::Event> for EventType { |
| | fn from(event: &libp2p_dcutr::Event) -> Self { |
| | match event { |
| | libp2p_dcutr::Event { |
| | remote_peer_id: _, |
| | result: Ok(_), |
| | } => EventType::DirectConnectionUpgradeSucceeded, |
| | libp2p_dcutr::Event { |
| | remote_peer_id: _, |
| | result: Err(_), |
| | } => EventType::DirectConnectionUpgradeFailed, |
| | } |
| | } |
| | } |
| |
|
| | impl super::Recorder<libp2p_dcutr::Event> for Metrics { |
| | fn record(&self, event: &libp2p_dcutr::Event) { |
| | self.events |
| | .get_or_create(&EventLabels { |
| | event: event.into(), |
| | }) |
| | .inc(); |
| | } |
| | } |
| |
|