Created
April 24, 2024 22:07
-
-
Save mobyjames/70dbdc64aa63b9a9295cb6a64ea2d99a to your computer and use it in GitHub Desktop.
Colyseus Diagnostic Info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import osUtils from "node-os-utils"; | |
import { matchMaker } from 'colyseus'; | |
async function getTotalConnections() { | |
const rooms = await matchMaker.query({}); | |
let total = rooms.reduce((acc, room) => { | |
return acc + room.clients; | |
}, 0); | |
return total; | |
} | |
async function getDiagnosticData() { | |
const cpuUsedPercent = Math.round(await osUtils.cpu.usage()); | |
const memoryUsedInfo = await osUtils.mem.used() | |
const memoryUsedPercent = Math.round(memoryUsedInfo.usedMemMb / memoryUsedInfo.totalMemMb * 100); | |
const connections = await getTotalConnections(); | |
return { | |
cpuUsedPercent, | |
memoryUsedPercent, | |
connections, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment