From fc23a048b8eede015f16d6b37e6c0adca62d7693 Mon Sep 17 00:00:00 2001 From: Myrotvorets Date: Sat, 14 Oct 2023 17:41:38 +0300 Subject: [PATCH] Bug fixes --- src/processmetrics.mts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/processmetrics.mts b/src/processmetrics.mts index 76a3914..a46163d 100644 --- a/src/processmetrics.mts +++ b/src/processmetrics.mts @@ -27,7 +27,7 @@ async function getMemoryStats(): Promise<[number, number]> { let vmrss, vmsize; const lines = (await readFile('/proc/self/status', 'utf-8')).split('\n'); for (const line of lines) { - const [key, value] = line.split(/[: ]+/u, 2); + const [key, value] = line.split(/[\s:]+/u, 2); if (key === 'VmRSS') { vmrss = +(value ?? NaN); } else if (key === 'VmSize') { @@ -95,7 +95,7 @@ export async function initProcessMetrics(): Promise { observer.observe(cpuTime, usage.systemCPUTime / 1e6, { state: 'system' }); // cpuUsage is in microseconds, hrtime is in nanoseconds - const elapsedUs = Number((observationTime - lastObservationTime) / 1000n); + const elapsedUs = Number((observationTime - lastObservationTime) * 1000n); observer.observe(cpuUtilization, (usage.userCPUTime - lastUsage.userCPUTime) / elapsedUs / cpuCount, { state: 'user', });