From ddc725d1a9aa5ae2dca30bf2b6d07b0d6d7a5ac6 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Wed, 21 Aug 2024 13:40:43 +0100 Subject: [PATCH] Add more data to stats footer --- crates/librqbit/src/session_stats/mod.rs | 2 ++ crates/librqbit/src/session_stats/snapshot.rs | 8 ++++++++ crates/librqbit/webui/src/api-types.ts | 3 +++ crates/librqbit/webui/src/components/Footer.tsx | 14 +++++++++++--- crates/librqbit/webui/src/stores/statsStore.ts | 3 +++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/crates/librqbit/src/session_stats/mod.rs b/crates/librqbit/src/session_stats/mod.rs index ef3d814..8cf5eb0 100644 --- a/crates/librqbit/src/session_stats/mod.rs +++ b/crates/librqbit/src/session_stats/mod.rs @@ -17,6 +17,7 @@ pub struct SessionStats { pub atomic: Arc, pub down_speed_estimator: SpeedEstimator, pub up_speed_estimator: SpeedEstimator, + pub startup_time: Instant, } impl SessionStats { @@ -25,6 +26,7 @@ impl SessionStats { atomic: Default::default(), down_speed_estimator: SpeedEstimator::new(5), up_speed_estimator: SpeedEstimator::new(5), + startup_time: Instant::now(), } } } diff --git a/crates/librqbit/src/session_stats/snapshot.rs b/crates/librqbit/src/session_stats/snapshot.rs index b2feb2d..6b5569a 100644 --- a/crates/librqbit/src/session_stats/snapshot.rs +++ b/crates/librqbit/src/session_stats/snapshot.rs @@ -1,3 +1,5 @@ +use std::sync::atomic::Ordering; + use serde::Serialize; use crate::torrent_state::{peers::stats::snapshot::AggregatePeerStats, stats::Speed}; @@ -6,9 +8,12 @@ use super::SessionStats; #[derive(Debug, Serialize)] pub struct SessionStatsSnapshot { + fetched_bytes: u64, + uploaded_bytes: u64, download_speed: Speed, upload_speed: Speed, peers: AggregatePeerStats, + uptime_seconds: u64, } impl From<&SessionStats> for SessionStatsSnapshot { @@ -16,7 +21,10 @@ impl From<&SessionStats> for SessionStatsSnapshot { Self { download_speed: s.down_speed_estimator.mbps().into(), upload_speed: s.up_speed_estimator.mbps().into(), + fetched_bytes: s.atomic.fetched_bytes.load(Ordering::Relaxed), + uploaded_bytes: s.atomic.uploaded_bytes.load(Ordering::Relaxed), peers: AggregatePeerStats::from(&s.atomic.peers), + uptime_seconds: s.startup_time.elapsed().as_secs(), } } } diff --git a/crates/librqbit/webui/src/api-types.ts b/crates/librqbit/webui/src/api-types.ts index 3d9488e..c62197a 100644 --- a/crates/librqbit/webui/src/api-types.ts +++ b/crates/librqbit/webui/src/api-types.ts @@ -46,7 +46,10 @@ export interface AggregatePeerStats { export interface SessionStats { download_speed: Speed; upload_speed: Speed; + fetched_bytes: number; + uploaded_bytes: number; peers: AggregatePeerStats; + uptime_seconds: number; } // Interface for the Torrent Stats API response diff --git a/crates/librqbit/webui/src/components/Footer.tsx b/crates/librqbit/webui/src/components/Footer.tsx index 186cab6..b248071 100644 --- a/crates/librqbit/webui/src/components/Footer.tsx +++ b/crates/librqbit/webui/src/components/Footer.tsx @@ -1,12 +1,20 @@ +import { formatBytes } from "../helper/formatBytes"; +import { formatSecondsToTime } from "../helper/formatSecondsToTime"; import { useStatsStore } from "../stores/statsStore"; -import { Speed } from "./Speed"; export const Footer: React.FC<{}> = () => { let stats = useStatsStore((stats) => stats.stats); return (
-
↓ {stats.download_speed.human_readable}
-
↑ {stats.upload_speed.human_readable}
+
+ ↓ {stats.download_speed.human_readable} (total{" "} + {formatBytes(stats.fetched_bytes)}) +
+
+ ↑ {stats.upload_speed.human_readable} (total{" "} + {formatBytes(stats.uploaded_bytes)}) +
+
up {formatSecondsToTime(stats.uptime_seconds)}
); }; diff --git a/crates/librqbit/webui/src/stores/statsStore.ts b/crates/librqbit/webui/src/stores/statsStore.ts index ebf2b4c..ddf7d1a 100644 --- a/crates/librqbit/webui/src/stores/statsStore.ts +++ b/crates/librqbit/webui/src/stores/statsStore.ts @@ -19,6 +19,9 @@ export const useStatsStore = create((set) => ({ queued: 0, seen: 0, }, + fetched_bytes: 0, + uploaded_bytes: 0, + uptime_seconds: 0, }, setStats: (stats) => { set({ stats });