Skip to content

Instantly share code, notes, and snippets.

@mobyjames
Created April 24, 2024 22:07
Show Gist options
  • Save mobyjames/70dbdc64aa63b9a9295cb6a64ea2d99a to your computer and use it in GitHub Desktop.
Save mobyjames/70dbdc64aa63b9a9295cb6a64ea2d99a to your computer and use it in GitHub Desktop.
Colyseus Diagnostic Info
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