Switch from systeminformation to os-utils to resolve bitdefender antivirus on windows, and reduce memory leak for monitor extension (#1282)
Co-authored-by: Hien To <tominhhien97@gmail.com>
This commit is contained in:
parent
843d1b4ff3
commit
45fdadf1ea
@ -32,9 +32,9 @@
|
||||
"@janhq/core": "file:../../core",
|
||||
"download-cli": "^1.1.1",
|
||||
"fetch-retry": "^5.0.6",
|
||||
"os-utils": "^0.0.14",
|
||||
"path-browserify": "^1.0.1",
|
||||
"rxjs": "^7.8.1",
|
||||
"systeminformation": "^5.21.20",
|
||||
"tcp-port-used": "^1.0.2",
|
||||
"ts-loader": "^9.5.0",
|
||||
"ulid": "^2.3.0"
|
||||
@ -50,6 +50,6 @@
|
||||
"bundleDependencies": [
|
||||
"tcp-port-used",
|
||||
"fetch-retry",
|
||||
"systeminformation"
|
||||
"os-utils"
|
||||
]
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ const path = require("path");
|
||||
const { exec, spawn } = require("child_process");
|
||||
const tcpPortUsed = require("tcp-port-used");
|
||||
const fetchRetry = require("fetch-retry")(global.fetch);
|
||||
const si = require("systeminformation");
|
||||
const osUtils = require("os-utils");
|
||||
const { readFileSync, writeFileSync, existsSync } = require("fs");
|
||||
|
||||
// The PORT to use for the Nitro subprocess
|
||||
@ -440,11 +440,10 @@ function spawnNitroProcess(nitroResourceProbe: any): Promise<any> {
|
||||
*/
|
||||
function getResourcesInfo(): Promise<ResourcesInfo> {
|
||||
return new Promise(async (resolve) => {
|
||||
const cpu = await si.cpu();
|
||||
// const mem = await si.mem();
|
||||
|
||||
const cpu = await osUtils.cpuCount();
|
||||
console.log("cpu: ", cpu);
|
||||
const response: ResourcesInfo = {
|
||||
numCpuPhysicalCore: cpu.physicalCores,
|
||||
numCpuPhysicalCore: cpu,
|
||||
memAvailable: 0,
|
||||
};
|
||||
resolve(response);
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@janhq/core": "file:../../core",
|
||||
"systeminformation": "^5.21.8",
|
||||
"os-utils": "^0.0.14",
|
||||
"ts-loader": "^9.5.0"
|
||||
},
|
||||
"files": [
|
||||
@ -26,6 +26,6 @@
|
||||
"README.md"
|
||||
],
|
||||
"bundleDependencies": [
|
||||
"systeminformation"
|
||||
"os-utils"
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,22 +1,32 @@
|
||||
const si = require("systeminformation");
|
||||
const os = require("os");
|
||||
const osUtils = require("os-utils");
|
||||
|
||||
const getResourcesInfo = () =>
|
||||
new Promise((resolve) => {
|
||||
const totalMemory = os.totalmem();
|
||||
const freeMemory = os.freemem();
|
||||
const usedMemory = totalMemory - freeMemory;
|
||||
|
||||
const getResourcesInfo = async () =>
|
||||
new Promise(async (resolve) => {
|
||||
const cpu = await si.cpu();
|
||||
const mem = await si.mem();
|
||||
// const gpu = await si.graphics();
|
||||
const response = {
|
||||
cpu,
|
||||
mem,
|
||||
// gpu,
|
||||
mem: {
|
||||
totalMemory,
|
||||
usedMemory,
|
||||
},
|
||||
};
|
||||
resolve(response);
|
||||
});
|
||||
|
||||
const getCurrentLoad = async () =>
|
||||
new Promise(async (resolve) => {
|
||||
const currentLoad = await si.currentLoad();
|
||||
resolve(currentLoad);
|
||||
const getCurrentLoad = () =>
|
||||
new Promise((resolve) => {
|
||||
osUtils.cpuUsage(function(v){
|
||||
const cpuPercentage = v * 100;
|
||||
const response = {
|
||||
cpu: {
|
||||
usage: cpuPercentage,
|
||||
},
|
||||
};
|
||||
resolve(response);
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
|
||||
@ -32,24 +32,26 @@ export default function useGetSystemResources() {
|
||||
const currentLoadInfor = await monitoring?.getCurrentLoad()
|
||||
|
||||
const ram =
|
||||
(resourceInfor?.mem?.active ?? 0) / (resourceInfor?.mem?.total ?? 1)
|
||||
if (resourceInfor?.mem?.active) setUsedRam(resourceInfor.mem.active)
|
||||
if (resourceInfor?.mem?.total) setTotalRam(resourceInfor.mem.total)
|
||||
(resourceInfor?.mem?.usedMemory ?? 0) /
|
||||
(resourceInfor?.mem?.totalMemory ?? 1)
|
||||
if (resourceInfor?.mem?.usedMemory) setUsedRam(resourceInfor.mem.usedMemory)
|
||||
if (resourceInfor?.mem?.totalMemory)
|
||||
setTotalRam(resourceInfor.mem.totalMemory)
|
||||
|
||||
setRam(Math.round(ram * 100))
|
||||
setCPU(Math.round(currentLoadInfor?.currentLoad ?? 0))
|
||||
setCpuUsage(Math.round(currentLoadInfor?.currentLoad ?? 0))
|
||||
setCPU(Math.round(currentLoadInfor?.cpu?.usage ?? 0))
|
||||
setCpuUsage(Math.round(currentLoadInfor?.cpu?.usage ?? 0))
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getSystemResources()
|
||||
|
||||
// Fetch interval - every 5s
|
||||
// Fetch interval - every 2s
|
||||
// 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()
|
||||
}, 5000)
|
||||
}, 2000)
|
||||
|
||||
// clean up interval
|
||||
return () => clearInterval(intervalId)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user