import { MemoryStick } from "lucide-react"; import { useTranslation } from "react-i18next"; import type { ServerMetrics } from "@/main-axios.ts"; import { SectionCard } from "@/components/section-card"; interface MemoryWidgetProps { metrics: ServerMetrics | null; metricsHistory: ServerMetrics[]; } function Sparkline({ history, current, }: { history: ServerMetrics[]; current: number | null; }) { const points = [ ...history.map((m) => m?.memory?.percent ?? 0), current ?? 0, ].slice(-20); if (points.length < 2) return null; const w = 300; const h = 48; const max = Math.max(...points, 1); const coords = points.map((v, i) => { const x = (i / (points.length - 1)) * w; const y = h - (v / max) * h; return `${x},${y}`; }); const d = `M ${coords.join(" L ")}`; const fill = `M 0,${h} L ${coords.join(" L ")} L ${w},${h} Z`; return (
); } export function MemoryWidget({ metrics, metricsHistory }: MemoryWidgetProps) { const { t } = useTranslation(); const percent = metrics?.memory?.percent ?? null; const usedGiB = metrics?.memory?.usedGiB ?? null; const totalGiB = metrics?.memory?.totalGiB ?? null; return ( } >
{percent !== null ? `${percent.toFixed(1)}%` : "N/A"} {usedGiB !== null && totalGiB !== null ? `${usedGiB.toFixed(1)} / ${totalGiB.toFixed(1)} GiB` : "N/A"}
{t("serverStats.swap")} N/A
{t("serverStats.free")} {usedGiB !== null && totalGiB !== null ? `${(totalGiB - usedGiB).toFixed(1)} GiB` : "N/A"}
); }