From c235ef65f371bb12d976115136c2cb66a7940df2 Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 29 Sep 2022 16:36:39 -0600 Subject: [PATCH] Monitoring bandwidth for 2 seconds when running status main. Updating archive's single-file call to use asyncio as well as fixing JSON error that used to be thrown. Trying two place for single-file executable. Adding more docs to bandwidth functions. Extracting reused functions out. Testing worker. Ordering bandwidth statuses by their name. Breaking down bandwidth by interface. Splitting download buttons to avoid overflow. Creating bandwidth worker which tracks server bandwidth usage to display on the status page. Testing get_bandwidth_info() with no psutil. Using psutil to fetch status. Adding bandwidth status. --- app/src/Dashboard.js | 12 +- app/src/components/Common.js | 18 +- app/src/components/Placeholder.js | 7 + app/src/components/Upload.js | 4 +- app/src/components/admin/Status.js | 126 ++++++++++---- docker/archive/main.py | 29 ++- main.py | 7 + requirements.txt | 3 +- wrolpi/root_api.py | 6 +- wrolpi/status.py | 271 ++++++++++++++++++++++++++++- wrolpi/test/test_status.py | 48 +++++ 11 files changed, 475 insertions(+), 56 deletions(-) diff --git a/app/src/Dashboard.js b/app/src/Dashboard.js index bdb1e7ce..865ebf46 100644 --- a/app/src/Dashboard.js +++ b/app/src/Dashboard.js @@ -6,8 +6,8 @@ import {DownloadMenu} from "./components/Upload"; import {FilesSearchView} from "./components/Files"; import {Header, Segment, Statistic, StatisticGroup} from "./components/Theme"; import {Link} from "react-router-dom"; -import {CPUUsageProgress} from "./components/admin/Status"; -import {Divider} from "semantic-ui-react"; +import {BandwidthProgressCombined, CPUUsageProgress} from "./components/admin/Status"; +import {ProgressPlaceholder} from "./components/Placeholder"; export function Dashboard() { useTitle('Dashboard'); @@ -69,15 +69,19 @@ function DashboardStatus() {
Status
+
Load
- - +
Bandwidth
+ {status && status['bandwidth'] ? + status['bandwidth'].map(i => ) : + } + diff --git a/app/src/components/Common.js b/app/src/components/Common.js index 988ac0b4..bb919e1a 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -355,8 +355,24 @@ export function humanFileSize(bytes, si = false, dp = 1) { return bytes.toFixed(dp) + ' ' + units[u]; } +export function humanBandwidth(bytes) { + // Convert bytes to Mbps and return a string. + bytes /= 125; + let size = 'Kbps'; + if (bytes > 1000) { + bytes /= 125_000; + size = 'Mbps'; + } + if (bytes > 1000) { + bytes /= 1000; + size = 'Gbps'; + } + bytes = Math.round(bytes); + return `${bytes} ${size}`; +} + export function humanNumber(num, dp = 1) { - // Convert large numbers to a more human readable format. + // Convert large numbers to a more human-readable format. // >> humanNumber(1000) // 1.0k // >> humanNumber(1500000) diff --git a/app/src/components/Placeholder.js b/app/src/components/Placeholder.js index b8da5ee6..84f16045 100644 --- a/app/src/components/Placeholder.js +++ b/app/src/components/Placeholder.js @@ -36,3 +36,10 @@ export function ChannelPlaceholder() { ) } + +export function ProgressPlaceholder() { + return + + + +} diff --git a/app/src/components/Upload.js b/app/src/components/Upload.js index 200356f4..f7481262 100644 --- a/app/src/components/Upload.js +++ b/app/src/components/Upload.js @@ -275,13 +275,13 @@ export function DownloadMenu({onOpen}) { onOpen(name) } - let body = ( + let body = (<>