From 09744818dc53a10c5cc39771ed78d1af8eea6895 Mon Sep 17 00:00:00 2001 From: MacRimi Date: Sat, 25 Oct 2025 18:09:48 +0200 Subject: [PATCH] Update AppImage --- AppImage/components/network-metrics.tsx | 59 +++++++++++++++++++ AppImage/components/network-traffic-chart.tsx | 12 ++-- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/AppImage/components/network-metrics.tsx b/AppImage/components/network-metrics.tsx index 59e156f..b984a63 100644 --- a/AppImage/components/network-metrics.tsx +++ b/AppImage/components/network-metrics.tsx @@ -153,6 +153,7 @@ export function NetworkMetrics() { const [selectedInterface, setSelectedInterface] = useState(null) const [timeframe, setTimeframe] = useState<"hour" | "day" | "week" | "month" | "year">("day") + const [interfaceTimeframe, setInterfaceTimeframe] = useState<"hour" | "day" | "week" | "month" | "year">("day") const [networkTotals, setNetworkTotals] = useState<{ received: number; sent: number }>({ received: 0, sent: 0 }) const { data: interfaceHistoricalData } = useSWR(`/api/node/metrics?timeframe=${timeframe}`, fetcher, { @@ -160,6 +161,15 @@ export function NetworkMetrics() { revalidateOnFocus: false, }) + const { data: selectedInterfaceData, isLoading: interfaceDataLoading } = useSWR( + selectedInterface ? `/api/network/${selectedInterface.name}/history?timeframe=${interfaceTimeframe}` : null, + fetcher, + { + refreshInterval: 30000, + revalidateOnFocus: false, + }, + ) + if (isLoading) { return (
@@ -642,6 +652,22 @@ export function NetworkMetrics() { {selectedInterface && (
+ {/* Timeframe Selector */} +
+ +
+ {/* Basic Information */}

Basic Information

@@ -773,6 +799,39 @@ export function NetworkMetrics() {
)} + {/* Network Traffic Chart */} + {selectedInterfaceData && ( +
+

+ Network Traffic -{" "} + {interfaceTimeframe === "hour" + ? "1 Hour" + : interfaceTimeframe === "day" + ? "24 Hours" + : interfaceTimeframe === "week" + ? "7 Days" + : interfaceTimeframe === "month" + ? "30 Days" + : "1 Year"} +

+ {interfaceDataLoading ? ( +
+
Loading historical data...
+
+ ) : ( +
+ { + // Optional: update totals if needed + }} + /> +
+ )} +
+ )} + {/* Traffic Statistics */}

Traffic since last boot

diff --git a/AppImage/components/network-traffic-chart.tsx b/AppImage/components/network-traffic-chart.tsx index d0c0c65..98fd89e 100644 --- a/AppImage/components/network-traffic-chart.tsx +++ b/AppImage/components/network-traffic-chart.tsx @@ -13,6 +13,7 @@ interface NetworkMetricsData { interface NetworkTrafficChartProps { timeframe: string + interfaceName?: string // Added optional interfaceName prop for specific interface data onTotalsCalculated?: (totals: { received: number; sent: number }) => void } @@ -36,7 +37,7 @@ const CustomNetworkTooltip = ({ active, payload, label }: any) => { return null } -export function NetworkTrafficChart({ timeframe, onTotalsCalculated }: NetworkTrafficChartProps) { +export function NetworkTrafficChart({ timeframe, interfaceName, onTotalsCalculated }: NetworkTrafficChartProps) { const [data, setData] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) @@ -47,7 +48,7 @@ export function NetworkTrafficChart({ timeframe, onTotalsCalculated }: NetworkTr useEffect(() => { fetchMetrics() - }, [timeframe]) + }, [timeframe, interfaceName]) const fetchMetrics = async () => { setLoading(true) @@ -56,12 +57,15 @@ export function NetworkTrafficChart({ timeframe, onTotalsCalculated }: NetworkTr try { const baseUrl = typeof window !== "undefined" ? `${window.location.protocol}//${window.location.hostname}:8008` : "" - const apiUrl = `${baseUrl}/api/node/metrics?timeframe=${timeframe}` + + const apiUrl = interfaceName + ? `${baseUrl}/api/network/${interfaceName}/history?timeframe=${timeframe}` + : `${baseUrl}/api/node/metrics?timeframe=${timeframe}` const response = await fetch(apiUrl) if (!response.ok) { - throw new Error(`Failed to fetch node metrics: ${response.status}`) + throw new Error(`Failed to fetch network metrics: ${response.status}`) } const result = await response.json()