Node status

This commit is contained in:
2025-12-27 14:03:51 +01:00
parent eed4a0e438
commit 1ab87edacd
5 changed files with 121 additions and 15 deletions
+52
View File
@@ -0,0 +1,52 @@
import { NextRequest, NextResponse } from "next/server";
import testAuth from "../auth";
import { StatusCodes } from "http-status-codes";
import si from "systeminformation";
export async function GET(req: NextRequest): Promise<NextResponse> {
const auth = await testAuth(req);
if (auth) {
return NextResponse.json(
{ message: auth },
{ status: StatusCodes.UNAUTHORIZED }
);
}
const [cpu, mem, load, disk, network] = await Promise.all([
si.cpu(),
si.mem(),
si.currentLoad(),
si.fsSize(),
si.networkStats(),
]);
return NextResponse.json({
message: "ok",
liveData: {
cpu: {
manufacturer: cpu.manufacturer,
brand: cpu.brand,
cores: cpu.cores,
usage: load.currentLoad,
},
memory: {
total: mem.total,
used: mem.used,
free: mem.free,
usage: ((mem.total - mem.free) / mem.total) * 100,
},
disk: disk.map((d) => ({
fs: d.fs,
size: d.size,
used: d.used,
usage: d.use,
})),
network: network.map((n) => ({
iface: n.iface,
rx: n.rx_bytes,
tx: n.tx_bytes,
})),
},
});
}
+18 -10
View File
@@ -87,13 +87,19 @@ const applications = [
memory: 48,
status: "pending" as const,
},
];
].slice(-5);
export default function OverviewPage() {
const [nodes, setNodes] = useState<NodeLiveData[]>([]);
useEffect(() => {
getLiveNodes().then(setNodes);
const fetchNodes = async () => {
const nodes = await getLiveNodes();
setNodes(nodes);
};
fetchNodes();
const interval = setInterval(fetchNodes, 3000);
return () => clearInterval(interval);
}, []);
return (
@@ -228,7 +234,7 @@ export default function OverviewPage() {
>
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between mb-3 gap-2">
<div className="flex items-center gap-2">
<StatusIndicator status={node.liveData.status} />
<StatusIndicator status={"running"} />
<span className="font-mono text-sm">{node.name}</span>
</div>
<span className="text-xs text-muted-foreground font-mono">
@@ -238,25 +244,27 @@ export default function OverviewPage() {
<div className="space-y-2">
<div className="flex items-center justify-between text-xs">
<span className="text-muted-foreground">CPU</span>
<span className="font-mono">{node.liveData.cpu}%</span>
<span className="font-mono">
{node.liveData.cpu.usage.toFixed(0)}%
</span>
</div>
<Progress
value={node.liveData.cpu}
value={node.liveData.cpu.usage}
className="[&>div]:bg-chart-1"
/>
<div className="flex items-center justify-between text-xs">
<span className="text-muted-foreground">Memory</span>
<span className="font-mono">{node.liveData.memory}%</span>
<span className="font-mono">
{node.liveData.memory.usage.toFixed(0)}%
</span>
</div>
<Progress
value={node.liveData.memory}
value={node.liveData.memory.usage}
className="w-full [&>div]:bg-chart-3"
/>
<div className="flex items-center justify-between text-xs pt-2 border-t border-border mt-2">
<span className="text-muted-foreground">Containers</span>
<span className="font-mono">
{node.liveData.containers}
</span>
<span className="font-mono">{6}</span>
</div>
</div>
</div>