From 3cd32081830ff0a4ca435489bb091529a3944f2c Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sat, 3 Aug 2024 10:25:00 -0700 Subject: [PATCH] server: cpuUsage not available on deno --- server/src/plugin/plugin-remote-stats.ts | 35 ++++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) 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({