diff --git a/server/src/plugin/plugin-remote-stats.ts b/server/src/plugin/plugin-remote-stats.ts index cf1350a3d..15de5c422 100644 --- a/server/src/plugin/plugin-remote-stats.ts +++ b/server/src/plugin/plugin-remote-stats.ts @@ -8,23 +8,28 @@ export interface PluginStats { export function startStatsUpdater(allMemoryStats: Map, updateStats: (stats: PluginStats) => void) { setInterval(() => { - const cpuUsage = process.cpuUsage(); - allMemoryStats.set(undefined, process.memoryUsage()); + let cpuUsage: NodeJS.CpuUsage; + let memoryUsage: NodeJS.MemoryUsage; + if (process.cpuUsage) { + cpuUsage = process.cpuUsage(); + allMemoryStats.set(undefined, process.memoryUsage()); - const memoryUsage: NodeJS.MemoryUsage = { - rss: 0, - heapTotal: 0, - heapUsed: 0, - external: 0, - arrayBuffers: 0, - } + memoryUsage = { + rss: 0, + heapTotal: 0, + heapUsed: 0, + external: 0, + arrayBuffers: 0, + } + + for (const mu of allMemoryStats.values()) { + memoryUsage.rss += mu.rss; + memoryUsage.heapTotal += mu.heapTotal; + memoryUsage.heapUsed += mu.heapUsed; + memoryUsage.external += mu.external; + memoryUsage.arrayBuffers += mu.arrayBuffers; + } - for (const mu of allMemoryStats.values()) { - memoryUsage.rss += mu.rss; - memoryUsage.heapTotal += mu.heapTotal; - memoryUsage.heapUsed += mu.heapUsed; - memoryUsage.external += mu.external; - memoryUsage.arrayBuffers += mu.arrayBuffers; } updateStats({