server is lagging for some reason and cpu is high, log cpu usage to track it

This commit is contained in:
Evan
2025-02-24 13:39:03 -08:00
parent 3c163140c2
commit 389e905813
3 changed files with 53 additions and 0 deletions
+16
View File
@@ -32,6 +32,7 @@ import crypto from "crypto";
dotenv.config();
import rateLimit from "express-rate-limit";
import { RateLimiterMemory } from "rate-limiter-flexible";
import * as si from "systeminformation";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@@ -385,6 +386,10 @@ app.use((err: Error, req: Request, res: Response, next: NextFunction) => {
function startServer() {
setInterval(() => tick(), 1000);
setInterval(() => updateLobbies(), 100);
setInterval(async () => {
await getCurrentCpuUsage();
console.log("---");
}, 5 * 1000);
initializeSecrets();
@@ -471,4 +476,15 @@ async function getSecret(secretName: string, ge: GameEnv) {
return version.payload?.data?.toString();
}
async function getCurrentCpuUsage(): Promise<void> {
const cpuData = await si.currentLoad();
console.log(`Current CPU Load: ${cpuData.currentLoad.toFixed(2)}%`);
console.log(
`Current CPU Load (User): ${cpuData.currentLoadUser.toFixed(2)}%`,
);
console.log(
`Current CPU Load (System): ${cpuData.currentLoadSystem.toFixed(2)}%`,
);
}
startServer();