import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import type { NodeWithStatus } from "@/types/node"; import { useMemo, memo } from "react"; interface InstanceProps { node: NodeWithStatus; } const formatUptime = (uptime: number) => { if (!uptime) return "N/A"; const days = Math.floor(uptime / 86400); const hours = Math.floor((uptime % 86400) / 3600); const minutes = Math.floor((uptime % 3600) / 60); const seconds = Math.floor(uptime % 60); let result = ""; if (days > 0) result += `${days} 天 `; if (hours > 0 || days > 0) result += `${hours} 时 `; if (minutes > 0 || hours > 0 || days > 0) result += `${minutes} 分 `; result += `${seconds} 秒`; return result.trim(); }; const formatBytes = (bytes: number, unit: "KB" | "MB" | "GB" = "GB") => { if (bytes === 0) return `0 ${unit}`; const k = 1024; switch (unit) { case "KB": return `${(bytes / k).toFixed(2)} KB`; case "MB": return `${(bytes / (k * k)).toFixed(2)} MB`; case "GB": return `${(bytes / (k * k * k)).toFixed(2)} GB`; default: return `${bytes} B`; } }; const Instance = memo(({ node }: InstanceProps) => { const { stats, isOnline } = useMemo(() => { return { stats: node.stats, isOnline: node.status === "online", }; }, [node]); return ( 详细信息

CPU

{`${node.cpu_name} (x${node.cpu_cores})`}

架构

{node.arch}

虚拟化

{node.virtualization}

GPU

{node.gpu_name || "N/A"}

操作系统

{node.os}

内存

{stats && isOnline ? `${formatBytes(stats.ram.used)} / ${formatBytes( node.mem_total )}` : `N/A / ${formatBytes(node.mem_total)}`}

交换

{stats && isOnline ? `${formatBytes(stats.swap.used, "MB")} / ${formatBytes( node.swap_total )}` : `N/A / ${formatBytes(node.swap_total)}`}

磁盘

{stats && isOnline ? `${formatBytes(stats.disk.used)} / ${formatBytes( node.disk_total )}` : `N/A / ${formatBytes(node.disk_total)}`}

网络

{stats && isOnline ? `↑ ${formatBytes(stats.network.up, "KB")}/s ↓ ${formatBytes( stats.network.down, "KB" )}/s` : "N/A"}

总流量

{stats && isOnline ? `↑ ${formatBytes(stats.network.totalUp)} ↓ ${formatBytes( stats.network.totalDown )}` : "N/A"}

运行时间

{formatUptime(stats?.uptime || 0)}

最后上报

{stats && isOnline ? new Date(stats.updated_at).toLocaleString() : "N/A"}

); }); export default Instance;