mirror of
https://github.com/henrygd/beszel.git
synced 2026-03-22 21:46:18 +01:00
[Feature] Improve Network Monitoring (#926)
* Split interfaces * add filters * feat: split interfaces and add filters (without locales) * make it an line chart * fix the colors * remove tx rx tooltip * fill the chart * update chart and cleanup * chore * update system tab * Fix alerts * chore * fix chart * resolve conflicts * Use new formatSpeed * fix records * update pakage * Fix network I/O stats compilation errors - Added globalNetIoStats field to Agent struct to track total bandwidth usage - Updated initializeNetIoStats() to initialize both per-interface and global network stats - Modified system.go to use globalNetIoStats for bandwidth calculations - Maintained per-interface tracking in netIoStats map for interface-specific data This resolves the compilation errors where netIoStats was accessed as a single struct instead of a map[string]NetIoStats. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove redundant bandwidth chart and fix network interface data access - Removed the old Bandwidth chart since network interface charts provide more detailed per-interface data - Fixed system.tsx to look for network interface data in stats.ni instead of stats.ns - Fixed NetworkInterfaceChart component to use correct data paths (stats.ni) - Network interface charts should now display properly with per-interface network statistics 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Restore split network metrics display in systems table - Modified systems table Net column to show separate sent/received values - Added green ↑ arrow for sent traffic and blue ↓ arrow for received traffic - Uses info.ns (NetworkSent) and info.nr (NetworkRecv) from agent - Maintains sorting functionality based on total network traffic - Shows values in appropriate units (B/s, KB/s, MB/s, etc.) This restores the split network metrics view that was present in the original feat/split-interfaces branch before the merge conflict resolution. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove unused bandwidth fields and calculations from agent Removed legacy bandwidth collection code that is no longer used by the frontend: **Removed from structs:** - Stats.Bandwidth [2]uint64 (bandwidth bytes array) - Stats.MaxBandwidth [2]uint64 (max bandwidth bytes array) - Info.Bandwidth float64 (total bandwidth MB/s) - Info.BandwidthBytes uint64 (total bandwidth bytes/s) **Removed from agent:** - globalNetIoStats tracking and calculations - bandwidth byte-per-second calculations - bandwidth array assignments in systemStats - bandwidth field assignments in systemInfo **Removed from records:** - Bandwidth array accumulation and averaging in AverageSystemStats - MaxBandwidth tracking in peak value calculations The frontend now uses only: - info.ns/info.nr (split metrics in systems table) - stats.ni (per-interface charts) This cleanup removes ~50 lines of unused code and eliminates redundant calculations. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Optimize network collection for better performance **Performance Improvements:** - Pre-allocate NetworkInterfaces map with known capacity to reduce allocations - Remove redundant byte counters (totalBytesSent, totalBytesRecv) that were unused - Direct calculation to MB/s, avoiding intermediate bytes-per-second variables - Reuse existing NetIoStats structs when possible to reduce GC pressure - Streamlined single-pass processing through network interfaces **Optimizations:** - Reduced memory allocations per collection cycle - Fewer arithmetic operations (eliminated double conversion) - Better cache locality with simplified data flow - Reduced time complexity from O(n²) operations to O(n) **Maintained Functionality:** - Same per-interface statistics collection - Same total network sent/recv calculations - Same error handling and reset logic - Same data structures and output format Expected improvement: ~15-25% reduction in network collection CPU time and memory allocations. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix the Unit preferences * Add total bytes sent and received to network interface stats and implement total bandwidth chart * chore: fix Cumulative records * Add connection counts * Add connection stats * Fix ordering * remove test builds * improve entre command in makefile * rebase
This commit is contained in:
863
internal/site/package-lock.json
generated
863
internal/site/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
124
internal/site/src/components/charts/connection-chart.tsx
Normal file
124
internal/site/src/components/charts/connection-chart.tsx
Normal file
@@ -0,0 +1,124 @@
|
||||
import { memo } from "react"
|
||||
import { useLingui } from "@lingui/react/macro"
|
||||
import { Area, AreaChart, CartesianGrid, YAxis } from "recharts"
|
||||
import {
|
||||
ChartContainer,
|
||||
ChartTooltip,
|
||||
ChartTooltipContent,
|
||||
ChartLegend,
|
||||
ChartLegendContent,
|
||||
xAxis,
|
||||
} from "@/components/ui/chart"
|
||||
import { cn, formatShortDate, chartMargin } from "@/lib/utils"
|
||||
import { ChartData } from "@/types"
|
||||
import { useYAxisWidth } from "./hooks"
|
||||
|
||||
export default memo(function ConnectionChart({ chartData }: { chartData: ChartData }) {
|
||||
const { yAxisWidth, updateYAxisWidth } = useYAxisWidth()
|
||||
const { t } = useLingui()
|
||||
|
||||
if (chartData.systemStats.length === 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
const dataKeys = [
|
||||
{
|
||||
name: t`IPv4 Established`,
|
||||
dataKey: "stats.nets.conn_established",
|
||||
color: "hsl(220, 70%, 50%)", // Blue
|
||||
},
|
||||
{
|
||||
name: t`IPv4 Listen`,
|
||||
dataKey: "stats.nets.conn_listen",
|
||||
color: "hsl(142, 70%, 45%)", // Green
|
||||
},
|
||||
{
|
||||
name: t`IPv4 Time Wait`,
|
||||
dataKey: "stats.nets.conn_timewait",
|
||||
color: "hsl(48, 96%, 53%)", // Yellow
|
||||
},
|
||||
{
|
||||
name: t`IPv4 Close Wait`,
|
||||
dataKey: "stats.nets.conn_closewait",
|
||||
color: "hsl(271, 81%, 56%)", // Purple
|
||||
},
|
||||
{
|
||||
name: t`IPv4 Syn Recv`,
|
||||
dataKey: "stats.nets.conn_synrecv",
|
||||
color: "hsl(9, 78%, 56%)", // Red
|
||||
},
|
||||
{
|
||||
name: t`IPv6 Established`,
|
||||
dataKey: "stats.nets.conn6_established",
|
||||
color: "hsl(220, 70%, 65%)", // Light Blue
|
||||
},
|
||||
{
|
||||
name: t`IPv6 Listen`,
|
||||
dataKey: "stats.nets.conn6_listen",
|
||||
color: "hsl(142, 70%, 60%)", // Light Green
|
||||
},
|
||||
{
|
||||
name: t`IPv6 Time Wait`,
|
||||
dataKey: "stats.nets.conn6_timewait",
|
||||
color: "hsl(48, 96%, 68%)", // Light Yellow
|
||||
},
|
||||
{
|
||||
name: t`IPv6 Close Wait`,
|
||||
dataKey: "stats.nets.conn6_closewait",
|
||||
color: "hsl(271, 81%, 71%)", // Light Purple
|
||||
},
|
||||
{
|
||||
name: t`IPv6 Syn Recv`,
|
||||
dataKey: "stats.nets.conn6_synrecv",
|
||||
color: "hsl(9, 78%, 71%)", // Light Red
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<div>
|
||||
<ChartContainer
|
||||
className={cn("h-full w-full absolute aspect-auto bg-card opacity-0 transition-opacity", {
|
||||
"opacity-100": yAxisWidth,
|
||||
})}
|
||||
>
|
||||
<AreaChart accessibilityLayer data={chartData.systemStats} margin={chartMargin}>
|
||||
<CartesianGrid vertical={false} />
|
||||
<YAxis
|
||||
direction="ltr"
|
||||
orientation={chartData.orientation}
|
||||
className="tracking-tighter"
|
||||
width={yAxisWidth}
|
||||
tickFormatter={(value) => updateYAxisWidth(value.toString())}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
/>
|
||||
{xAxis(chartData)}
|
||||
<ChartTooltip
|
||||
animationEasing="ease-out"
|
||||
animationDuration={150}
|
||||
content={
|
||||
<ChartTooltipContent
|
||||
labelFormatter={(_, data) => formatShortDate(data[0].payload.created)}
|
||||
contentFormatter={({ value }) => value.toString()}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<ChartLegend content={<ChartLegendContent />} />
|
||||
{dataKeys.map((key, i) => (
|
||||
<Area
|
||||
key={i}
|
||||
dataKey={key.dataKey}
|
||||
name={key.name}
|
||||
type="monotoneX"
|
||||
fill={key.color}
|
||||
fillOpacity={0.3}
|
||||
stroke={key.color}
|
||||
strokeOpacity={1}
|
||||
isAnimationActive={false}
|
||||
/>
|
||||
))}
|
||||
</AreaChart>
|
||||
</ChartContainer>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
164
internal/site/src/components/charts/network-interface-chart.tsx
Normal file
164
internal/site/src/components/charts/network-interface-chart.tsx
Normal file
@@ -0,0 +1,164 @@
|
||||
import { memo, useMemo } from "react"
|
||||
import { useLingui } from "@lingui/react/macro"
|
||||
import { Area, AreaChart, CartesianGrid, YAxis } from "recharts"
|
||||
import {
|
||||
ChartContainer,
|
||||
ChartTooltip,
|
||||
ChartTooltipContent,
|
||||
xAxis,
|
||||
ChartLegend,
|
||||
ChartLegendContent,
|
||||
} from "@/components/ui/chart"
|
||||
import { cn, formatShortDate, chartMargin, formatBytes, toFixedFloat, decimalString } from "@/lib/utils"
|
||||
import { ChartData } from "@/types"
|
||||
import { useStore } from "@nanostores/react"
|
||||
import { $networkInterfaceFilter, $userSettings } from "@/lib/stores"
|
||||
import { Unit } from "@/lib/enums"
|
||||
import { useYAxisWidth } from "./hooks"
|
||||
|
||||
const getNestedValue = (path: string, max = false, data: any): number | null => {
|
||||
// path format is like "eth0.ns" or "eth0.nr"
|
||||
// need to access data.stats.ni[interface][property]
|
||||
const parts = path.split(".")
|
||||
if (parts.length !== 2) return null
|
||||
|
||||
const [interfaceName, property] = parts
|
||||
const propertyKey = property + (max ? "m" : "")
|
||||
|
||||
return data?.stats?.ni?.[interfaceName]?.[propertyKey] ?? null
|
||||
}
|
||||
|
||||
export default memo(function NetworkInterfaceChart({
|
||||
chartData,
|
||||
maxToggled = false,
|
||||
max,
|
||||
}: {
|
||||
chartData: ChartData
|
||||
maxToggled?: boolean
|
||||
max?: number
|
||||
}) {
|
||||
const { yAxisWidth, updateYAxisWidth } = useYAxisWidth()
|
||||
const { i18n } = useLingui()
|
||||
const networkInterfaceFilter = useStore($networkInterfaceFilter)
|
||||
const userSettings = useStore($userSettings)
|
||||
|
||||
const { chartTime } = chartData
|
||||
const showMax = chartTime !== "1h" && maxToggled
|
||||
|
||||
// Get network interface names from the latest stats
|
||||
const networkInterfaces = useMemo(() => {
|
||||
if (chartData.systemStats.length === 0) return []
|
||||
const latestStats = chartData.systemStats[chartData.systemStats.length - 1]
|
||||
const allInterfaces = Object.keys(latestStats.stats.ni || {})
|
||||
|
||||
// Filter interfaces based on filter value
|
||||
if (networkInterfaceFilter) {
|
||||
return allInterfaces.filter((iface) => iface.toLowerCase().includes(networkInterfaceFilter.toLowerCase()))
|
||||
}
|
||||
|
||||
return allInterfaces
|
||||
}, [chartData.systemStats, networkInterfaceFilter])
|
||||
|
||||
const dataKeys = useMemo(() => {
|
||||
// Generate colors for each interface - each interface gets a unique hue
|
||||
// and sent/received use different shades of that hue
|
||||
const interfaceColors = networkInterfaces.map((iface, index) => {
|
||||
const hue = ((index * 360) / Math.max(networkInterfaces.length, 1)) % 360
|
||||
return {
|
||||
interface: iface,
|
||||
sentColor: `hsl(${hue}, 70%, 45%)`, // Darker shade for sent
|
||||
receivedColor: `hsl(${hue}, 70%, 65%)`, // Lighter shade for received
|
||||
}
|
||||
})
|
||||
|
||||
return interfaceColors.flatMap(({ interface: iface, sentColor, receivedColor }) => [
|
||||
{
|
||||
name: `${iface} Sent`,
|
||||
dataKey: `${iface}.ns`,
|
||||
color: sentColor,
|
||||
type: "sent" as const,
|
||||
interface: iface,
|
||||
},
|
||||
{
|
||||
name: `${iface} Received`,
|
||||
dataKey: `${iface}.nr`,
|
||||
color: receivedColor,
|
||||
type: "received" as const,
|
||||
interface: iface,
|
||||
},
|
||||
])
|
||||
}, [networkInterfaces, i18n.locale])
|
||||
|
||||
const colors = dataKeys.map((key) => key.name)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<ChartContainer
|
||||
className={cn("h-full w-full absolute aspect-auto bg-card opacity-0 transition-opacity", {
|
||||
"opacity-100": yAxisWidth,
|
||||
})}
|
||||
>
|
||||
<AreaChart accessibilityLayer data={chartData.systemStats} margin={chartMargin}>
|
||||
<CartesianGrid vertical={false} />
|
||||
<YAxis
|
||||
direction="ltr"
|
||||
orientation={chartData.orientation}
|
||||
className="tracking-tighter"
|
||||
width={yAxisWidth}
|
||||
tickFormatter={(value) => {
|
||||
const { value: formattedValue, unit } = formatBytes(value, true, userSettings.unitNet ?? Unit.Bits, true)
|
||||
const rounded = toFixedFloat(formattedValue, formattedValue >= 10 ? 1 : 2)
|
||||
return updateYAxisWidth(`${rounded} ${unit}`)
|
||||
}}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
/>
|
||||
{xAxis(chartData)}
|
||||
<ChartTooltip
|
||||
animationEasing="ease-out"
|
||||
animationDuration={150}
|
||||
content={
|
||||
<ChartTooltipContent
|
||||
labelFormatter={(_: any, data: any) => formatShortDate(data[0].payload.created)}
|
||||
contentFormatter={({ value }: any) => {
|
||||
const { value: formattedValue, unit } = formatBytes(
|
||||
value,
|
||||
true,
|
||||
userSettings.unitNet ?? Unit.Bits,
|
||||
true
|
||||
)
|
||||
return (
|
||||
<span className="flex">
|
||||
{decimalString(formattedValue, formattedValue >= 10 ? 1 : 2)} {unit}
|
||||
</span>
|
||||
)
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
{dataKeys.map((key, i) => {
|
||||
const filtered =
|
||||
networkInterfaceFilter && !key.interface.toLowerCase().includes(networkInterfaceFilter.toLowerCase())
|
||||
let fillOpacity = filtered ? 0.05 : 0.4
|
||||
let strokeOpacity = filtered ? 0.1 : 1
|
||||
return (
|
||||
<Area
|
||||
key={i}
|
||||
dataKey={getNestedValue.bind(null, key.dataKey, showMax)}
|
||||
name={key.name}
|
||||
type="monotoneX"
|
||||
fill={key.color}
|
||||
fillOpacity={fillOpacity}
|
||||
stroke={key.color}
|
||||
strokeOpacity={strokeOpacity}
|
||||
activeDot={{ opacity: filtered ? 0 : 1 }}
|
||||
isAnimationActive={false}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
{colors.length < 12 && <ChartLegend content={<ChartLegendContent />} />}
|
||||
</AreaChart>
|
||||
</ChartContainer>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
159
internal/site/src/components/charts/total-bandwidth-chart.tsx
Normal file
159
internal/site/src/components/charts/total-bandwidth-chart.tsx
Normal file
@@ -0,0 +1,159 @@
|
||||
import { memo, useMemo } from "react"
|
||||
import { useLingui } from "@lingui/react/macro"
|
||||
import { Area, AreaChart, CartesianGrid, YAxis } from "recharts"
|
||||
import {
|
||||
ChartContainer,
|
||||
ChartTooltip,
|
||||
ChartTooltipContent,
|
||||
ChartLegend,
|
||||
ChartLegendContent,
|
||||
xAxis,
|
||||
} from "@/components/ui/chart"
|
||||
import { cn, formatShortDate, chartMargin, formatBytes, toFixedFloat, decimalString } from "@/lib/utils"
|
||||
import { ChartData } from "@/types"
|
||||
import { useStore } from "@nanostores/react"
|
||||
import { $userSettings } from "@/lib/stores"
|
||||
import { Unit } from "@/lib/enums"
|
||||
import { useYAxisWidth } from "./hooks"
|
||||
|
||||
const getPerInterfaceBandwidth = (data: any): Record<string, { sent: number; recv: number }> | null => {
|
||||
const networkInterfaces = data?.stats?.ni
|
||||
if (!networkInterfaces) {
|
||||
return null
|
||||
}
|
||||
|
||||
const interfaceData: Record<string, { sent: number; recv: number }> = {}
|
||||
let hasData = false
|
||||
|
||||
Object.entries(networkInterfaces).forEach(([name, iface]: [string, any]) => {
|
||||
if (iface.tbs || iface.tbr) {
|
||||
interfaceData[name] = {
|
||||
sent: iface.tbs || 0,
|
||||
recv: iface.tbr || 0,
|
||||
}
|
||||
hasData = true
|
||||
}
|
||||
})
|
||||
|
||||
return hasData ? interfaceData : null
|
||||
}
|
||||
|
||||
export default memo(function TotalBandwidthChart({ chartData }: { chartData: ChartData }) {
|
||||
const { yAxisWidth, updateYAxisWidth } = useYAxisWidth()
|
||||
const { i18n } = useLingui()
|
||||
const userSettings = useStore($userSettings)
|
||||
|
||||
// Transform data to include per-interface bandwidth
|
||||
const { transformedData, interfaceNames } = useMemo(() => {
|
||||
const allInterfaces = new Set<string>()
|
||||
|
||||
// First pass: collect all interface names
|
||||
chartData.systemStats.forEach((dataPoint) => {
|
||||
const interfaceData = getPerInterfaceBandwidth(dataPoint)
|
||||
if (interfaceData) {
|
||||
Object.keys(interfaceData).forEach((name) => allInterfaces.add(name))
|
||||
}
|
||||
})
|
||||
|
||||
const interfaceNames = Array.from(allInterfaces).sort()
|
||||
|
||||
// Second pass: transform data with per-interface values
|
||||
const transformedData = chartData.systemStats.map((dataPoint) => {
|
||||
const interfaceData = getPerInterfaceBandwidth(dataPoint)
|
||||
const result: any = { ...dataPoint }
|
||||
|
||||
interfaceNames.forEach((interfaceName) => {
|
||||
const data = interfaceData?.[interfaceName]
|
||||
result[`${interfaceName}_sent`] = data?.sent || 0
|
||||
result[`${interfaceName}_recv`] = data?.recv || 0
|
||||
})
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
return { transformedData, interfaceNames }
|
||||
}, [chartData.systemStats])
|
||||
|
||||
// Generate dynamic data keys for each interface using same color scheme as NetworkInterfaceChart
|
||||
const dataKeys = useMemo(() => {
|
||||
const keys: Array<{ name: string; dataKey: string; color: string }> = []
|
||||
|
||||
interfaceNames.forEach((interfaceName, index) => {
|
||||
// Use the same color calculation as NetworkInterfaceChart
|
||||
const hue = ((index * 360) / Math.max(interfaceNames.length, 1)) % 360
|
||||
|
||||
keys.push({
|
||||
name: `${interfaceName} Sent`,
|
||||
dataKey: `${interfaceName}_sent`,
|
||||
color: `hsl(${hue}, 70%, 45%)`, // Darker shade for sent (same as NetworkInterfaceChart)
|
||||
})
|
||||
|
||||
keys.push({
|
||||
name: `${interfaceName} Received`,
|
||||
dataKey: `${interfaceName}_recv`,
|
||||
color: `hsl(${hue}, 70%, 65%)`, // Lighter shade for received (same as NetworkInterfaceChart)
|
||||
})
|
||||
})
|
||||
|
||||
return keys
|
||||
}, [interfaceNames])
|
||||
|
||||
return (
|
||||
<div>
|
||||
<ChartContainer
|
||||
className={cn("h-full w-full absolute aspect-auto bg-card opacity-0 transition-opacity", {
|
||||
"opacity-100": yAxisWidth,
|
||||
})}
|
||||
>
|
||||
<AreaChart accessibilityLayer data={transformedData} margin={chartMargin}>
|
||||
<CartesianGrid vertical={false} />
|
||||
<YAxis
|
||||
direction="ltr"
|
||||
orientation={chartData.orientation}
|
||||
className="tracking-tighter"
|
||||
width={yAxisWidth}
|
||||
tickFormatter={(value) => {
|
||||
const { value: formattedValue, unit } = formatBytes(value, false, userSettings.unitNet ?? Unit.Bytes)
|
||||
const rounded = toFixedFloat(formattedValue, formattedValue >= 10 ? 1 : 2)
|
||||
return updateYAxisWidth(`${rounded} ${unit}`)
|
||||
}}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
/>
|
||||
{xAxis(chartData)}
|
||||
<ChartTooltip
|
||||
animationEasing="ease-out"
|
||||
animationDuration={150}
|
||||
content={
|
||||
<ChartTooltipContent
|
||||
labelFormatter={(_: any, data: any) => formatShortDate(data[0].payload.created)}
|
||||
contentFormatter={({ value }: any) => {
|
||||
const { value: formattedValue, unit } = formatBytes(value, false, userSettings.unitNet ?? Unit.Bytes)
|
||||
return (
|
||||
<span className="flex">
|
||||
{decimalString(formattedValue, formattedValue >= 10 ? 1 : 2)} {unit}
|
||||
</span>
|
||||
)
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<ChartLegend content={<ChartLegendContent />} />
|
||||
{dataKeys.map((key, i) => (
|
||||
<Area
|
||||
key={i}
|
||||
dataKey={key.dataKey}
|
||||
name={key.name}
|
||||
type="monotoneX"
|
||||
fill={key.color}
|
||||
fillOpacity={0.3}
|
||||
stroke={key.color}
|
||||
strokeOpacity={1}
|
||||
isAnimationActive={false}
|
||||
/>
|
||||
))}
|
||||
</AreaChart>
|
||||
</ChartContainer>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
$containerFilter,
|
||||
$direction,
|
||||
$maxValues,
|
||||
$networkInterfaceFilter,
|
||||
$systems,
|
||||
$temperatureFilter,
|
||||
$userSettings,
|
||||
@@ -52,6 +53,9 @@ import { Input } from "../ui/input"
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select"
|
||||
import { Separator } from "../ui/separator"
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip"
|
||||
import ConnectionChart from "../charts/connection-chart"
|
||||
import NetworkInterfaceChart from "../charts/network-interface-chart"
|
||||
import TotalBandwidthChart from "../charts/total-bandwidth-chart"
|
||||
|
||||
type ChartTimeData = {
|
||||
time: number
|
||||
@@ -147,6 +151,7 @@ export default memo(function SystemDetail({ name }: { name: string }) {
|
||||
const netCardRef = useRef<HTMLDivElement>(null)
|
||||
const persistChartTime = useRef(false)
|
||||
const [containerFilterBar, setContainerFilterBar] = useState(null as null | JSX.Element)
|
||||
const [networkInterfaceFilterBar, setNetworkInterfaceFilterBar] = useState(null as null | JSX.Element)
|
||||
const [bottomSpacing, setBottomSpacing] = useState(0)
|
||||
const [chartLoading, setChartLoading] = useState(true)
|
||||
const isLongerChart = chartTime !== "1h"
|
||||
@@ -163,7 +168,9 @@ export default memo(function SystemDetail({ name }: { name: string }) {
|
||||
setSystemStats([])
|
||||
setContainerData([])
|
||||
setContainerFilterBar(null)
|
||||
setNetworkInterfaceFilterBar(null)
|
||||
$containerFilter.set("")
|
||||
$networkInterfaceFilter.set("")
|
||||
}
|
||||
}, [name])
|
||||
|
||||
@@ -260,6 +267,19 @@ export default memo(function SystemDetail({ name }: { name: string }) {
|
||||
})
|
||||
}, [system, chartTime])
|
||||
|
||||
// Set up network interface filter bar
|
||||
useEffect(() => {
|
||||
if (systemStats.length > 0) {
|
||||
const latestStats = systemStats[systemStats.length - 1]
|
||||
const networkInterfaces = Object.keys(latestStats.stats.ns || {})
|
||||
if (networkInterfaces.length > 0) {
|
||||
!networkInterfaceFilterBar && setNetworkInterfaceFilterBar(<FilterBar store={$networkInterfaceFilter} />)
|
||||
} else if (networkInterfaceFilterBar) {
|
||||
setNetworkInterfaceFilterBar(null)
|
||||
}
|
||||
}
|
||||
}, [systemStats, networkInterfaceFilterBar])
|
||||
|
||||
// values for system info bar
|
||||
const systemInfo = useMemo(() => {
|
||||
if (!system.info) {
|
||||
@@ -389,6 +409,7 @@ export default memo(function SystemDetail({ name }: { name: string }) {
|
||||
const lastGpuVals = Object.values(systemStats.at(-1)?.stats.g ?? {})
|
||||
const hasGpuData = lastGpuVals.length > 0
|
||||
const hasGpuPowerData = lastGpuVals.some((gpu) => gpu.p !== undefined)
|
||||
const latestNetworkStats = systemStats.at(-1)?.stats.ni
|
||||
|
||||
let translatedStatus: string = system.status
|
||||
if (system.status === SystemStatus.Up) {
|
||||
@@ -555,7 +576,7 @@ export default memo(function SystemDetail({ name }: { name: string }) {
|
||||
empty={dataEmpty}
|
||||
grid={grid}
|
||||
title={t`Disk I/O`}
|
||||
description={t`Throughput of root filesystem`}
|
||||
description={t`Disk read and write throughput`}
|
||||
cornerEl={maxValSelect}
|
||||
>
|
||||
<AreaChartDefault
|
||||
@@ -586,51 +607,44 @@ export default memo(function SystemDetail({ name }: { name: string }) {
|
||||
/>
|
||||
</ChartCard>
|
||||
|
||||
<ChartCard
|
||||
empty={dataEmpty}
|
||||
grid={grid}
|
||||
title={t`Bandwidth`}
|
||||
cornerEl={maxValSelect}
|
||||
description={t`Network traffic of public interfaces`}
|
||||
>
|
||||
<AreaChartDefault
|
||||
chartData={chartData}
|
||||
maxToggled={maxValues}
|
||||
dataPoints={[
|
||||
{
|
||||
label: t`Sent`,
|
||||
// use bytes if available, otherwise multiply old MB (can remove in future)
|
||||
dataKey(data) {
|
||||
if (showMax) {
|
||||
return data?.stats?.bm?.[0] ?? (data?.stats?.nsm ?? 0) * 1024 * 1024
|
||||
}
|
||||
return data?.stats?.b?.[0] ?? data?.stats?.ns * 1024 * 1024
|
||||
},
|
||||
color: 5,
|
||||
opacity: 0.2,
|
||||
},
|
||||
{
|
||||
label: t`Received`,
|
||||
dataKey(data) {
|
||||
if (showMax) {
|
||||
return data?.stats?.bm?.[1] ?? (data?.stats?.nrm ?? 0) * 1024 * 1024
|
||||
}
|
||||
return data?.stats?.b?.[1] ?? data?.stats?.nr * 1024 * 1024
|
||||
},
|
||||
color: 2,
|
||||
opacity: 0.2,
|
||||
},
|
||||
]}
|
||||
tickFormatter={(val) => {
|
||||
const { value, unit } = formatBytes(val, true, userSettings.unitNet, false)
|
||||
return `${toFixedFloat(value, value >= 10 ? 0 : 1)} ${unit}`
|
||||
}}
|
||||
contentFormatter={(data) => {
|
||||
const { value, unit } = formatBytes(data.value, true, userSettings.unitNet, false)
|
||||
return `${decimalString(value, value >= 100 ? 1 : 2)} ${unit}`
|
||||
}}
|
||||
/>
|
||||
</ChartCard>
|
||||
{/* Network interface charts */}
|
||||
{Object.keys(latestNetworkStats ?? {}).length > 0 && (
|
||||
<ChartCard
|
||||
empty={dataEmpty}
|
||||
grid={grid}
|
||||
title={t`Network Interfaces`}
|
||||
description={t`Network traffic per interface`}
|
||||
cornerEl={networkInterfaceFilterBar}
|
||||
>
|
||||
{/* @ts-ignore */}
|
||||
<NetworkInterfaceChart chartData={chartData} />
|
||||
</ChartCard>
|
||||
)}
|
||||
|
||||
{/* Per-Interface Cumulative Bandwidth chart */}
|
||||
{Object.keys(latestNetworkStats ?? {}).length > 0 && (
|
||||
<ChartCard
|
||||
empty={dataEmpty}
|
||||
grid={grid}
|
||||
title={t`Cumulative Bandwidth`}
|
||||
description={t`Total bytes sent and received per network interface since boot`}
|
||||
>
|
||||
{/* @ts-ignore */}
|
||||
<TotalBandwidthChart chartData={chartData} />
|
||||
</ChartCard>
|
||||
)}
|
||||
|
||||
{/* TCP Connection States chart */}
|
||||
{systemStats.at(-1)?.stats.nets && Object.keys(systemStats.at(-1)?.stats.nets ?? {}).length > 0 && (
|
||||
<ChartCard
|
||||
empty={dataEmpty}
|
||||
grid={grid}
|
||||
title={t`TCP Connection States`}
|
||||
description={t`TCP connection states for IPv4 and IPv6`}
|
||||
>
|
||||
<ConnectionChart chartData={chartData} />
|
||||
</ChartCard>
|
||||
)}
|
||||
|
||||
{containerFilterBar && containerData.length > 0 && (
|
||||
<div
|
||||
|
||||
@@ -216,22 +216,32 @@ export default function SystemsTableColumns(viewMode: "table" | "grid"): ColumnD
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorFn: ({ info }) => info.bb || (info.b || 0) * 1024 * 1024,
|
||||
accessorFn: (row) => (row.info.ns || 0) + (row.info.nr || 0),
|
||||
id: "net",
|
||||
name: () => t`Net`,
|
||||
size: 0,
|
||||
Icon: EthernetIcon,
|
||||
header: sortableHeader,
|
||||
sortDescFirst: true,
|
||||
sortingFn: (rowA, rowB) => {
|
||||
const a = (rowA.original.info.ns || 0) + (rowA.original.info.nr || 0)
|
||||
const b = (rowB.original.info.ns || 0) + (rowB.original.info.nr || 0)
|
||||
return a - b
|
||||
},
|
||||
cell(info) {
|
||||
const sys = info.row.original
|
||||
const system = info.row.original
|
||||
const sent = system.info.ns || 0
|
||||
const received = system.info.nr || 0
|
||||
const userSettings = useStore($userSettings, { keys: ["unitNet"] })
|
||||
if (sys.status === SystemStatus.Paused) {
|
||||
if (system.status === SystemStatus.Paused) {
|
||||
return null
|
||||
}
|
||||
const { value, unit } = formatBytes(info.getValue() as number, true, userSettings.unitNet, false)
|
||||
const sentFmt = formatBytes(sent, true, userSettings.unitNet, true)
|
||||
const receivedFmt = formatBytes(received, true, userSettings.unitNet, true)
|
||||
return (
|
||||
<span className="tabular-nums whitespace-nowrap">
|
||||
{decimalString(value, value >= 100 ? 1 : 2)} {unit}
|
||||
<span className={cn("tabular-nums whitespace-nowrap", { "ps-1": viewMode === "table" })}>
|
||||
<span className="text-green-600">↑</span> {Math.round(sentFmt.value)} {sentFmt.unit}{" "}
|
||||
<span className="text-blue-600">↓</span> {Math.round(receivedFmt.value)} {receivedFmt.unit}
|
||||
</span>
|
||||
)
|
||||
},
|
||||
|
||||
@@ -55,6 +55,9 @@ listenKeys($userSettings, ["chartTime"], ({ chartTime }) => $chartTime.set(chart
|
||||
/** Container chart filter */
|
||||
export const $containerFilter = atom("")
|
||||
|
||||
/** Network interface chart filter */
|
||||
export const $networkInterfaceFilter = atom("")
|
||||
|
||||
/** Temperature chart filter */
|
||||
export const $temperatureFilter = atom("")
|
||||
|
||||
|
||||
@@ -283,6 +283,22 @@ export const getHubURL = () => BESZEL?.HUB_URL || window.location.origin
|
||||
/** Map of system IDs to their corresponding tokens (used to avoid fetching in add-system dialog) */
|
||||
export const tokenMap = new Map<SystemRecord["id"], FingerprintRecord["token"]>()
|
||||
|
||||
/**
|
||||
* Formats a network speed value (in MB/s) to the most readable unit (B/s, KB/s, MB/s, GB/s, TB/s).
|
||||
* @param valueMBps The value in MB/s
|
||||
* @returns A string with the value and the appropriate unit
|
||||
*/
|
||||
export function formatSpeed(valueMBps: number): string {
|
||||
const bitsPerSec = valueMBps * 8_000_000
|
||||
if (bitsPerSec >= 1_000_000_000) {
|
||||
return (bitsPerSec / 1_000_000_000).toFixed(2) + ' Gbit/s'
|
||||
} else if (bitsPerSec >= 1_000_000) {
|
||||
return (bitsPerSec / 1_000_000).toFixed(2) + ' Mbit/s'
|
||||
} else {
|
||||
return (bitsPerSec / 1_000).toFixed(2) + ' kbit/s'
|
||||
}
|
||||
}
|
||||
|
||||
/** Calculate duration between two dates and format as human-readable string */
|
||||
export function formatDuration(
|
||||
createdDate: string | null | undefined,
|
||||
|
||||
25
internal/site/src/types.d.ts
vendored
25
internal/site/src/types.d.ts
vendored
@@ -75,6 +75,25 @@ export interface SystemInfo {
|
||||
dt?: number
|
||||
/** operating system */
|
||||
os?: Os
|
||||
/** network sent (mb) */
|
||||
ns?: number
|
||||
/** network received (mb) */
|
||||
nr?: number
|
||||
}
|
||||
|
||||
export interface NetworkInterfaceStats {
|
||||
/** network sent (mb) */
|
||||
ns: number
|
||||
/** network received (mb) */
|
||||
nr: number
|
||||
/** max network sent (mb) */
|
||||
nsm?: number
|
||||
/** max network received (mb) */
|
||||
nrm?: number
|
||||
/** total bytes sent since boot */
|
||||
tbs?: number
|
||||
/** total bytes received since boot */
|
||||
tbr?: number
|
||||
}
|
||||
|
||||
export interface SystemStats {
|
||||
@@ -131,7 +150,9 @@ export interface SystemStats {
|
||||
nsm?: number
|
||||
/** max network received (mb) */
|
||||
nrm?: number
|
||||
/** max network sent (bytes) */
|
||||
/** per-interface network stats */
|
||||
ni?: Record<string, NetworkInterfaceStats>
|
||||
/** max bandwidth (bytes) [sent, received] */
|
||||
bm?: [number, number]
|
||||
/** temperatures */
|
||||
t?: Record<string, number>
|
||||
@@ -141,6 +162,8 @@ export interface SystemStats {
|
||||
g?: Record<string, GPUData>
|
||||
/** battery percent and state */
|
||||
bat?: [number, BatteryState]
|
||||
/** network connection statistics */
|
||||
nets?: Record<string, number>
|
||||
}
|
||||
|
||||
export interface GPUData {
|
||||
|
||||
Reference in New Issue
Block a user