Node status
This commit is contained in:
@@ -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
@@ -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>
|
||||
|
||||
+23
-5
@@ -11,10 +11,28 @@ export interface NodeLiveData {
|
||||
ip: string;
|
||||
key: string;
|
||||
liveData: {
|
||||
status: "running" | "pending" | "error";
|
||||
cpu: number;
|
||||
memory: number;
|
||||
disk: number;
|
||||
containers: number;
|
||||
cpu: {
|
||||
manufacturer: string;
|
||||
brand: string;
|
||||
cores: number;
|
||||
usage: number;
|
||||
};
|
||||
memory: {
|
||||
total: number;
|
||||
used: number;
|
||||
free: number;
|
||||
usage: number;
|
||||
};
|
||||
disk: {
|
||||
fs: string;
|
||||
size: number;
|
||||
used: number;
|
||||
usage: number;
|
||||
}[];
|
||||
network: {
|
||||
iface: string;
|
||||
rx: number;
|
||||
tx: number;
|
||||
}[];
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user