diff --git a/agent/main.go b/agent/main.go index 33bafc8..d31cdd6 100644 --- a/agent/main.go +++ b/agent/main.go @@ -73,6 +73,8 @@ func getSystemStats() (*SystemInfo, *SystemStats) { systemStats.MemUsed = bytesToGigabytes(v.Used) systemStats.MemBuffCache = bytesToGigabytes(v.Total - v.Free - v.Used) systemStats.MemPct = twoDecimals(v.UsedPercent) + systemStats.Swap = bytesToGigabytes(v.SwapTotal) + systemStats.SwapUsed = bytesToGigabytes(v.SwapTotal - v.SwapFree) } // disk usage diff --git a/agent/types.go b/agent/types.go index 50291a7..1d48eb0 100644 --- a/agent/types.go +++ b/agent/types.go @@ -25,6 +25,8 @@ type SystemStats struct { MemUsed float64 `json:"mu"` MemPct float64 `json:"mp"` MemBuffCache float64 `json:"mb"` + Swap float64 `json:"s"` + SwapUsed float64 `json:"su"` Disk float64 `json:"d"` DiskUsed float64 `json:"du"` DiskPct float64 `json:"dp"` diff --git a/hub/site/src/components/charts/swap-chart.tsx b/hub/site/src/components/charts/swap-chart.tsx new file mode 100644 index 0000000..fad4906 --- /dev/null +++ b/hub/site/src/components/charts/swap-chart.tsx @@ -0,0 +1,82 @@ +import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from 'recharts' + +import { ChartContainer, ChartTooltip, ChartTooltipContent } from '@/components/ui/chart' +import { + chartTimeData, + cn, + formatShortDate, + toFixedWithoutTrailingZeros, + useYaxisWidth, +} from '@/lib/utils' +// import Spinner from '../spinner' +import { useStore } from '@nanostores/react' +import { $chartTime } from '@/lib/stores' +import { SystemStatsRecord } from '@/types' +import { useMemo, useRef } from 'react' + +export default function SwapChart({ + ticks, + systemData, +}: { + ticks: number[] + systemData: SystemStatsRecord[] +}) { + const chartTime = useStore($chartTime) + const chartRef = useRef(null) + const yAxisWidth = useYaxisWidth(chartRef) + + const yAxisSet = useMemo(() => yAxisWidth !== 180, [yAxisWidth]) + + return ( +
+ + + + toFixedWithoutTrailingZeros(systemData.at(-1)?.stats.s ?? 0.04, 2)]} + width={yAxisWidth} + tickLine={false} + axisLine={false} + unit={' GB'} + /> + + formatShortDate(data[0].payload.created)} + indicator="line" + /> + } + /> + + + +
+ ) +} diff --git a/hub/site/src/components/routes/system.tsx b/hub/site/src/components/routes/system.tsx index 8a59077..87ee304 100644 --- a/hub/site/src/components/routes/system.tsx +++ b/hub/site/src/components/routes/system.tsx @@ -19,6 +19,7 @@ const DiskChart = lazy(() => import('../charts/disk-chart')) const DiskIoChart = lazy(() => import('../charts/disk-io-chart')) const BandwidthChart = lazy(() => import('../charts/bandwidth-chart')) const ContainerNetChart = lazy(() => import('../charts/container-net-chart')) +const SwapChart = lazy(() => import('../charts/swap-chart')) export default function ServerDetail({ name }: { name: string }) { const systems = useStore($systems) @@ -231,6 +232,12 @@ export default function ServerDetail({ name }: { name: string }) { )} + {(systemStats.at(-1)?.stats.s ?? 0) > 0 && ( + + + + )} +