|
1 | | -use iroh_metrics::{Counter, MetricsGroup}; |
| 1 | +use iroh_metrics::{Counter, Histogram, MetricsGroup}; |
2 | 2 | use serde::{Deserialize, Serialize}; |
3 | 3 |
|
4 | 4 | /// Enum of metrics for the module |
5 | 5 | // TODO(frando): Add description doc strings for each metric. |
6 | 6 | #[allow(missing_docs)] |
7 | | -#[derive(Debug, Default, Serialize, Deserialize, MetricsGroup)] |
| 7 | +#[derive(Debug, Serialize, Deserialize, MetricsGroup)] |
8 | 8 | #[non_exhaustive] |
9 | 9 | #[metrics(name = "magicsock")] |
10 | 10 | pub struct Metrics { |
@@ -77,4 +77,88 @@ pub struct Metrics { |
77 | 77 | pub connection_handshake_success: Counter, |
78 | 78 | /// Number of connections with a successful handshake that became direct. |
79 | 79 | pub connection_became_direct: Counter, |
| 80 | + |
| 81 | + /* |
| 82 | + * Path Congestion Metrics |
| 83 | + */ |
| 84 | + /// Number of times a path was marked as outdated due to consecutive ping failures. |
| 85 | + pub path_marked_outdated: Counter, |
| 86 | + /// Number of ping failures recorded across all paths. |
| 87 | + pub path_ping_failures: Counter, |
| 88 | + /// Number of consecutive failure resets (path recovered). |
| 89 | + pub path_failure_resets: Counter, |
| 90 | + /// Histogram of packet loss rates (0.0-1.0) observed on UDP paths. |
| 91 | + pub path_packet_loss_rate: Histogram, |
| 92 | + /// Histogram of RTT variance (in milliseconds) as a congestion indicator. |
| 93 | + pub path_rtt_variance_ms: Histogram, |
| 94 | + /// Histogram of path quality scores (0.0-1.0). |
| 95 | + pub path_quality_score: Histogram, |
| 96 | +} |
| 97 | + |
| 98 | +impl Default for Metrics { |
| 99 | + fn default() -> Self { |
| 100 | + Self { |
| 101 | + update_direct_addrs: Counter::default(), |
| 102 | + send_ipv4: Counter::default(), |
| 103 | + send_ipv6: Counter::default(), |
| 104 | + send_relay: Counter::default(), |
| 105 | + send_relay_error: Counter::default(), |
| 106 | + send_data: Counter::default(), |
| 107 | + send_data_network_down: Counter::default(), |
| 108 | + recv_data_relay: Counter::default(), |
| 109 | + recv_data_ipv4: Counter::default(), |
| 110 | + recv_data_ipv6: Counter::default(), |
| 111 | + recv_datagrams: Counter::default(), |
| 112 | + recv_gro_datagrams: Counter::default(), |
| 113 | + send_disco_udp: Counter::default(), |
| 114 | + send_disco_relay: Counter::default(), |
| 115 | + sent_disco_udp: Counter::default(), |
| 116 | + sent_disco_relay: Counter::default(), |
| 117 | + sent_disco_ping: Counter::default(), |
| 118 | + sent_disco_pong: Counter::default(), |
| 119 | + sent_disco_call_me_maybe: Counter::default(), |
| 120 | + recv_disco_bad_key: Counter::default(), |
| 121 | + recv_disco_bad_parse: Counter::default(), |
| 122 | + recv_disco_udp: Counter::default(), |
| 123 | + recv_disco_relay: Counter::default(), |
| 124 | + recv_disco_ping: Counter::default(), |
| 125 | + recv_disco_pong: Counter::default(), |
| 126 | + recv_disco_call_me_maybe: Counter::default(), |
| 127 | + recv_disco_call_me_maybe_bad_disco: Counter::default(), |
| 128 | + relay_home_change: Counter::default(), |
| 129 | + num_direct_conns_added: Counter::default(), |
| 130 | + num_direct_conns_removed: Counter::default(), |
| 131 | + num_relay_conns_added: Counter::default(), |
| 132 | + num_relay_conns_removed: Counter::default(), |
| 133 | + actor_tick_main: Counter::default(), |
| 134 | + actor_tick_msg: Counter::default(), |
| 135 | + actor_tick_re_stun: Counter::default(), |
| 136 | + actor_tick_portmap_changed: Counter::default(), |
| 137 | + actor_tick_direct_addr_heartbeat: Counter::default(), |
| 138 | + actor_link_change: Counter::default(), |
| 139 | + actor_tick_other: Counter::default(), |
| 140 | + nodes_contacted: Counter::default(), |
| 141 | + nodes_contacted_directly: Counter::default(), |
| 142 | + connection_handshake_success: Counter::default(), |
| 143 | + connection_became_direct: Counter::default(), |
| 144 | + path_marked_outdated: Counter::default(), |
| 145 | + path_ping_failures: Counter::default(), |
| 146 | + path_failure_resets: Counter::default(), |
| 147 | + path_packet_loss_rate: packet_loss_buckets(), |
| 148 | + path_rtt_variance_ms: rtt_variance_buckets(), |
| 149 | + path_quality_score: quality_score_buckets(), |
| 150 | + } |
| 151 | + } |
| 152 | +} |
| 153 | + |
| 154 | +fn packet_loss_buckets() -> Histogram { |
| 155 | + Histogram::new(vec![0.0, 0.01, 0.05, 0.1, 0.2, 0.5, 1.0]) |
| 156 | +} |
| 157 | + |
| 158 | +fn rtt_variance_buckets() -> Histogram { |
| 159 | + Histogram::new(vec![0.0, 1.0, 5.0, 10.0, 20.0, 50.0, 100.0, 200.0]) |
| 160 | +} |
| 161 | + |
| 162 | +fn quality_score_buckets() -> Histogram { |
| 163 | + Histogram::new(vec![0.0, 0.3, 0.5, 0.7, 0.85, 0.95, 1.0]) |
80 | 164 | } |
0 commit comments