import React from "react"; import { Cpu } from "lucide-react"; import { useTranslation } from "react-i18next"; import type { ServerMetrics } from "@/main-axios.ts"; import { SectionCard } from "@/components/section-card"; interface CpuWidgetProps { metrics: ServerMetrics | null; metricsHistory: ServerMetrics[]; } function Sparkline({ history, current, }: { history: ServerMetrics[]; current: number | null; }) { const points = [ ...history.map((m) => m?.cpu?.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 CpuWidget({ metrics, metricsHistory }: CpuWidgetProps) { const { t } = useTranslation(); const percent = metrics?.cpu?.percent ?? null; const cores = metrics?.cpu?.cores ?? null; const load = metrics?.cpu?.load ?? null; return ( } >
{percent !== null ? `${percent.toFixed(1)}%` : "N/A"} {cores !== null ? t("serverStats.cpuCores", { count: cores }) : t("serverStats.naCpus")}
{load && (
{t("serverStats.loadAvg")}
{load[0].toFixed(2)}  {load[1].toFixed(2)}   {load[2].toFixed(2)}
)}
); }