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
+35
View File
@@ -45,6 +45,7 @@
"pureimage": "^0.4.13",
"raphael": "^2.3.0",
"rate-limiter-flexible": "^5.0.5",
"systeminformation": "^5.25.11",
"twemoji": "^14.0.2",
"uuid": "^10.0.0",
"wheelnav": "^1.7.1",
@@ -63,6 +64,7 @@
"@types/node": "^22.10.2",
"@types/pg": "^8.11.11",
"@types/sinon": "^17.0.3",
"@types/systeminformation": "^3.23.1",
"@types/uuid": "^10.0.0",
"@types/ws": "^8.5.11",
"autoprefixer": "^10.4.20",
@@ -4836,6 +4838,13 @@
"dev": true,
"license": "MIT"
},
"node_modules/@types/systeminformation": {
"version": "3.23.1",
"resolved": "https://registry.npmjs.org/@types/systeminformation/-/systeminformation-3.23.1.tgz",
"integrity": "sha512-0/y5m3PQLhQL7UM8MEvwFuLoTT6k5bamcZyjap12S0iHb33ngKfDDqCSnIaCaKWvRE41R/9BsZov1aE6hvcpEg==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/tough-cookie": {
"version": "4.0.5",
"resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz",
@@ -15320,6 +15329,32 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/systeminformation": {
"version": "5.25.11",
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-5.25.11.tgz",
"integrity": "sha512-jI01fn/t47rrLTQB0FTlMCC+5dYx8o0RRF+R4BPiUNsvg5OdY0s9DKMFmJGrx5SwMZQ4cag0Gl6v8oycso9b/g==",
"license": "MIT",
"os": [
"darwin",
"linux",
"win32",
"freebsd",
"openbsd",
"netbsd",
"sunos",
"android"
],
"bin": {
"systeminformation": "lib/cli.js"
},
"engines": {
"node": ">=8.0.0"
},
"funding": {
"type": "Buy me a coffee",
"url": "https://www.buymeacoffee.com/systeminfo"
}
},
"node_modules/tailwindcss": {
"version": "3.4.17",
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.17.tgz",
+2
View File
@@ -30,6 +30,7 @@
"@types/node": "^22.10.2",
"@types/pg": "^8.11.11",
"@types/sinon": "^17.0.3",
"@types/systeminformation": "^3.23.1",
"@types/uuid": "^10.0.0",
"@types/ws": "^8.5.11",
"autoprefixer": "^10.4.20",
@@ -109,6 +110,7 @@
"pureimage": "^0.4.13",
"raphael": "^2.3.0",
"rate-limiter-flexible": "^5.0.5",
"systeminformation": "^5.25.11",
"twemoji": "^14.0.2",
"uuid": "^10.0.0",
"wheelnav": "^1.7.1",
+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();