feat(admin): analytics redis cache, shared ops health, ticket queue clarity
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
474de0717b
commit
58fae1f90f
38 files changed
+348
-245
No files matched your search
@@ -1,59 +1,16 @@
|
||||
import net from "node:net";
|
||||
import { NextResponse } from "next/server";
|
||||
import { env } from "@/env";
|
||||
import { fetchOpsHealth } from "@/lib/admin/ops-health";
|
||||
import { withAdmin } from "@/lib/api-handler";
|
||||
import { PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
function checkRcon(): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
const host = env.RCON_HOST;
|
||||
const port = env.RCON_PORT;
|
||||
|
||||
const socket = new net.Socket();
|
||||
const timeout = setTimeout(() => {
|
||||
socket.destroy();
|
||||
resolve(false);
|
||||
}, 3000);
|
||||
|
||||
socket.connect(port, host, () => {
|
||||
clearTimeout(timeout);
|
||||
socket.destroy();
|
||||
resolve(true);
|
||||
});
|
||||
|
||||
socket.on("error", () => {
|
||||
clearTimeout(timeout);
|
||||
socket.destroy();
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const GET = withAdmin({ permission: PERMS.DEVOPS_VIEW }, async () => {
|
||||
// DB health
|
||||
let dbOk = false;
|
||||
let dbLatency = 0;
|
||||
try {
|
||||
const start = Date.now();
|
||||
await prisma.$queryRaw`SELECT 1`;
|
||||
dbLatency = Date.now() - start;
|
||||
dbOk = true;
|
||||
} catch {
|
||||
dbOk = false;
|
||||
}
|
||||
|
||||
// Emulator health (RCON TCP check)
|
||||
const emulator = await checkRcon();
|
||||
|
||||
// Online users
|
||||
const onlineUsers = await prisma.user.count({ where: { online: "1" } });
|
||||
const health = await fetchOpsHealth();
|
||||
|
||||
return NextResponse.json({
|
||||
database: dbOk,
|
||||
dbLatency,
|
||||
emulator,
|
||||
onlineUsers,
|
||||
database: health.dbOk,
|
||||
dbLatency: health.dbLatencyMs,
|
||||
emulator: health.emulatorOk,
|
||||
onlineUsers: health.onlineUsers,
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user