|
| 1 | +use std::fmt; |
1 | 2 | use std::net::SocketAddr; |
2 | 3 | use std::time::Duration; |
3 | 4 |
|
| 5 | +use torrust_tracker_metrics::label::{LabelName, LabelSet, LabelValue}; |
4 | 6 | use torrust_tracker_primitives::service_binding::ServiceBinding; |
5 | 7 |
|
6 | 8 | pub mod sender; |
@@ -38,6 +40,17 @@ pub enum UdpRequestKind { |
38 | 40 | Scrape, |
39 | 41 | } |
40 | 42 |
|
| 43 | +impl fmt::Display for UdpRequestKind { |
| 44 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 45 | + let proto_str = match self { |
| 46 | + UdpRequestKind::Connect => "connect", |
| 47 | + UdpRequestKind::Announce => "announce", |
| 48 | + UdpRequestKind::Scrape => "scrape", |
| 49 | + }; |
| 50 | + write!(f, "{proto_str}") |
| 51 | + } |
| 52 | +} |
| 53 | + |
41 | 54 | #[derive(Debug, PartialEq, Eq, Clone)] |
42 | 55 | pub enum UdpResponseKind { |
43 | 56 | Ok { |
@@ -76,3 +89,22 @@ impl ConnectionContext { |
76 | 89 | self.server_service_binding.bind_address() |
77 | 90 | } |
78 | 91 | } |
| 92 | + |
| 93 | +impl From<ConnectionContext> for LabelSet { |
| 94 | + fn from(connection_context: ConnectionContext) -> Self { |
| 95 | + LabelSet::from([ |
| 96 | + ( |
| 97 | + LabelName::new("server_binding_protocol"), |
| 98 | + LabelValue::new(&connection_context.server_service_binding.protocol().to_string()), |
| 99 | + ), |
| 100 | + ( |
| 101 | + LabelName::new("server_binding_ip"), |
| 102 | + LabelValue::new(&connection_context.server_service_binding.bind_address().ip().to_string()), |
| 103 | + ), |
| 104 | + ( |
| 105 | + LabelName::new("server_binding_port"), |
| 106 | + LabelValue::new(&connection_context.server_service_binding.bind_address().port().to_string()), |
| 107 | + ), |
| 108 | + ]) |
| 109 | + } |
| 110 | +} |
0 commit comments