From 0a7e26d5fb55d9bc869b7291d0bbaaf2ab5340db Mon Sep 17 00:00:00 2001 From: hiento09 <136591877+hiento09@users.noreply.github.com> Date: Wed, 3 Jan 2024 02:09:17 +0700 Subject: [PATCH] Fix memory on mac included cached and swap (#1298) * Fix memory on mac included cached and swap * set inteval monitor to 0.5s --------- Co-authored-by: Hien To --- extensions/monitoring-extension/package.json | 4 +-- extensions/monitoring-extension/src/module.ts | 28 +++++++++---------- web/hooks/useGetSystemResources.ts | 4 +-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/extensions/monitoring-extension/package.json b/extensions/monitoring-extension/package.json index 4fc51d578c..9935e536ee 100644 --- a/extensions/monitoring-extension/package.json +++ b/extensions/monitoring-extension/package.json @@ -17,7 +17,7 @@ }, "dependencies": { "@janhq/core": "file:../../core", - "os-utils": "^0.0.14", + "node-os-utils": "^1.3.7", "ts-loader": "^9.5.0" }, "files": [ @@ -26,6 +26,6 @@ "README.md" ], "bundleDependencies": [ - "os-utils" + "node-os-utils" ] } diff --git a/extensions/monitoring-extension/src/module.ts b/extensions/monitoring-extension/src/module.ts index 18b3b6c494..310e7359c0 100644 --- a/extensions/monitoring-extension/src/module.ts +++ b/extensions/monitoring-extension/src/module.ts @@ -1,25 +1,25 @@ const os = require("os"); -const osUtils = require("os-utils"); +const nodeOsUtils = require("node-os-utils"); const getResourcesInfo = () => new Promise((resolve) => { - const totalMemory = os.totalmem(); - const freeMemory = os.freemem(); - const usedMemory = totalMemory - freeMemory; - - const response = { - mem: { - totalMemory, - usedMemory, - }, - }; - resolve(response); + nodeOsUtils.mem.used() + .then(ramUsedInfo => { + const totalMemory = ramUsedInfo.totalMemMb * 1024 * 1024; + const usedMemory = ramUsedInfo.usedMemMb * 1024 * 1024; + const response = { + mem: { + totalMemory, + usedMemory, + }, + }; + resolve(response); + }) }); const getCurrentLoad = () => new Promise((resolve) => { - osUtils.cpuUsage(function(v){ - const cpuPercentage = v * 100; + nodeOsUtils.cpu.usage().then(cpuPercentage =>{ const response = { cpu: { usage: cpuPercentage, diff --git a/web/hooks/useGetSystemResources.ts b/web/hooks/useGetSystemResources.ts index 74f8e6c407..9d6716480d 100644 --- a/web/hooks/useGetSystemResources.ts +++ b/web/hooks/useGetSystemResources.ts @@ -46,12 +46,12 @@ export default function useGetSystemResources() { useEffect(() => { getSystemResources() - // Fetch interval - every 2s + // Fetch interval - every 0.5s // TODO: Will we really need this? // There is a possibility that this will be removed and replaced by the process event hook? const intervalId = setInterval(() => { getSystemResources() - }, 2000) + }, 500) // clean up interval return () => clearInterval(intervalId)