From 42d38d5d46f6d8850f97d5e90a82eb0ac7d3a2d1 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 24 Oct 2026 06:43:16 +0200 Subject: add throughput stats --- src/api/peers.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/api/peers.rs') diff --git a/src/api/peers.rs b/src/api/peers.rs index 5b7d576..0305647 100644 --- a/src/api/peers.rs +++ b/src/api/peers.rs @@ -70,6 +70,18 @@ pub(crate) struct PeerStatus { /// since it was last listed). traffic: PeerTraffic, incidents: Incidents, + /// Smoothed sync throughput (`swarm::throughput`); absent before the first large + /// exchange. + sync_throughput: Option, +} + +#[derive(Debug, Serialize, ToSchema)] +#[serde(rename_all = "camelCase")] +pub(crate) struct ThroughputInfo { + bytes_per_sec: f64, + samples: u32, + /// Age of the last sample. + secs_ago: u64, } #[derive(Debug, Serialize, ToSchema)] @@ -122,6 +134,16 @@ pub(crate) async fn list_peers( .effective(&public_key, now, state.timing.rtt_fresh_for()) .map(|rtt| rtt.as_secs_f64() * 1000.0); let traffic = state.traffic.peer(&public_key).unwrap_or_default(); + let sync_throughput = state + .throughput + .lock() + .unwrap_or_else(|poisoned| poisoned.into_inner()) + .get(&public_key) + .map(|estimate| ThroughputInfo { + bytes_per_sec: estimate.bytes_per_sec.round(), + samples: estimate.samples, + secs_ago: now.saturating_duration_since(estimate.at).as_secs(), + }); let ps = peer_state_mutex.lock().await; let (status, dormant_for_secs) = match ps.liveness { @@ -149,6 +171,7 @@ pub(crate) async fn list_peers( rtt_ms, traffic, incidents: ps.incidents, + sync_throughput, }); } -- cgit v1.3.1