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,
})),
},
});
}