diff --git a/src/app/api/status/route.ts b/src/app/api/status/route.ts index da426a0..cc10a22 100644 --- a/src/app/api/status/route.ts +++ b/src/app/api/status/route.ts @@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server"; import testAuth from "../auth"; import { StatusCodes } from "http-status-codes"; import si from "systeminformation"; +import { NodeLiveData } from "@/lib/types"; export async function GET(req: NextRequest): Promise { const auth = await testAuth(req); @@ -21,6 +22,10 @@ export async function GET(req: NextRequest): Promise { si.networkStats(), ]); + const disks = await si.fsSize(); + + const root = disks.find((d) => d.mount === "/" || d.fs.includes("disk3")); + return NextResponse.json({ message: "ok", liveData: { @@ -36,7 +41,12 @@ export async function GET(req: NextRequest): Promise { free: mem.free, usage: ((mem.total - mem.free) / mem.total) * 100, }, - disk: disk.map((d) => ({ + disk: { + used: (root?.size || 0) - (root?.available || 0), + size: root?.size || 0, + available: root?.available || 0, + }, + disks: disk.map((d) => ({ fs: d.fs, size: d.size, used: d.used, @@ -48,5 +58,5 @@ export async function GET(req: NextRequest): Promise { tx: n.tx_bytes, })), }, - }); + } as NodeLiveData); } diff --git a/src/app/nodes/page.tsx b/src/app/nodes/page.tsx index 973de4b..2cc30ff 100644 --- a/src/app/nodes/page.tsx +++ b/src/app/nodes/page.tsx @@ -4,62 +4,49 @@ import { DashboardLayout } from "@/components/dashboard/DashboardLayout"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; -import { StatusIndicator } from "@/components/dashboard/StatusIndicator"; import { Server, Plus, Settings, Trash2 } from "lucide-react"; import { Progress } from "@/components/ui/progress"; +import { Node, NodeLiveData } from "@/lib/types"; +import { useEffect, useState } from "react"; +import { getLiveNodes } from "@/core/client/node"; +import { formatBytes } from "@/lib/format"; -const nodes = [ - { - id: "node-01", - name: "node-01", - hostname: "dockship-node-01.local", - ip: "10.0.1.10", - os: "Ubuntu 22.04 LTS", - docker: "24.0.7", - cpu: { cores: 8, usage: 72 }, - memory: { total: "32 GB", used: "21.8 GB", percentage: 68 }, - disk: { total: "500 GB", used: "245 GB", percentage: 49 }, - containers: 8, - status: "running" as const, - labels: ["production", "primary"], - }, - { - id: "node-02", - name: "node-02", - hostname: "dockship-node-02.local", - ip: "10.0.1.11", - os: "Ubuntu 22.04 LTS", - docker: "24.0.7", - cpu: { cores: 8, usage: 45 }, - memory: { total: "32 GB", used: "16.6 GB", percentage: 52 }, - disk: { total: "500 GB", used: "178 GB", percentage: 36 }, - containers: 6, - status: "running" as const, - labels: ["production"], - }, - { - id: "node-03", - name: "node-03", - hostname: "dockship-node-03.local", - ip: "10.0.1.12", - os: "Ubuntu 22.04 LTS", - docker: "24.0.7", - cpu: { cores: 16, usage: 89 }, - memory: { total: "64 GB", used: "54.4 GB", percentage: 85 }, - disk: { total: "1 TB", used: "612 GB", percentage: 61 }, - containers: 12, - status: "running" as const, - labels: ["production", "high-memory"], - }, -]; +function DiskUsage({ liveData }: NodeLiveData) { + const usage = (liveData.disk.used / liveData.disk.size) * 100; + + return ( +
+
Disk
+
{usage.toFixed(0)}%
+ +
+ {formatBytes(liveData.disk.used)} / {formatBytes(liveData.disk.size)} +
+
+ ); +} export default function NodesPage() { + const [nodes, setNodes] = useState<(NodeLiveData & Node)[]>([]); + + useEffect(() => { + const fetchNodes = async () => { + const nodes = await getLiveNodes(); + setNodes(nodes); + }; + fetchNodes(); + const interval = setInterval(fetchNodes, 3000); + return () => clearInterval(interval); + }, []); + return (
{nodes.length} nodes - {nodes.filter((n) => n.status === "running").length} online + + {/* {nodes.filter((n) => n.status === "running").length} online */} +
@@ -102,19 +94,21 @@ export default function NodesPage() {
{/* System Info */}
-
System
+
+ System +
OS - {node.os} + {/* {node.os} */}
Docker - {node.docker} + {/* {node.docker} */}
Containers - {node.containers} + {/* {node.containers} */}
@@ -122,35 +116,43 @@ export default function NodesPage() { {/* CPU */}
- CPU ({node.cpu.cores} cores) + CPU ({node.liveData.cpu.cores} cores)
-
{node.cpu.usage}%
- +
+ {node.liveData.cpu.usage.toFixed(0)}% +
+
{/* Memory */}
-
Memory
-
{node.memory.percentage}%
- +
+ Memory +
+
+ {node.liveData.memory.usage.toFixed(0)}% +
+
- {node.memory.used} / {node.memory.total} + {formatBytes(node.liveData.memory.used)} /{" "} + {formatBytes(node.liveData.memory.total)}
{/* Disk */} -
-
Disk
-
{node.disk.percentage}%
- -
- {node.disk.used} / {node.disk.total} -
-
+ {/* Quick Actions */}
-
Quick Actions
+
+ Quick Actions +