diff options
| author | tv <tv@krebsco.de> | 2026-10-24 06:43:16 +0200 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-24 06:43:16 +0200 |
| commit | 42d38d5d46f6d8850f97d5e90a82eb0ac7d3a2d1 (patch) | |
| tree | cd14e8adb226e52e64b3be27843b0c18373a034d /src/api | |
| parent | c59f213282517e3ab6fb631a7d8e3f9b91a1c5eb (diff) | |
add throughput stats
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/mod.rs | 1 | ||||
| -rw-r--r-- | src/api/peers.rs | 23 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/api/mod.rs b/src/api/mod.rs index 95d63aa..85427b0 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -159,6 +159,7 @@ fn response_for_value( crate::transport::traffic::ByKind, crate::transport::traffic::Counter, crate::state::Incidents, + peers::ThroughputInfo, ) ), tags( 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<ThroughputInfo>, +} + +#[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, }); } |
