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",
|
"@janhq/core": "file:../../core",
|
||||||
"download-cli": "^1.1.1",
|
"download-cli": "^1.1.1",
|
||||||
"fetch-retry": "^5.0.6",
|
"fetch-retry": "^5.0.6",
|
||||||
|
"os-utils": "^0.0.14",
|
||||||
"path-browserify": "^1.0.1",
|
"path-browserify": "^1.0.1",
|
||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
"systeminformation": "^5.21.20",
|
|
||||||
"tcp-port-used": "^1.0.2",
|
"tcp-port-used": "^1.0.2",
|
||||||
"ts-loader": "^9.5.0",
|
"ts-loader": "^9.5.0",
|
||||||
"ulid": "^2.3.0"
|
"ulid": "^2.3.0"
|
||||||
@ -50,6 +50,6 @@
|
|||||||
"bundleDependencies": [
|
"bundleDependencies": [
|
||||||
"tcp-port-used",
|
"tcp-port-used",
|
||||||
"fetch-retry",
|
"fetch-retry",
|
||||||
"systeminformation"
|
"os-utils"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ const path = require("path");
|
|||||||
const { exec, spawn } = require("child_process");
|
const { exec, spawn } = require("child_process");
|
||||||
const tcpPortUsed = require("tcp-port-used");
|
const tcpPortUsed = require("tcp-port-used");
|
||||||
const fetchRetry = require("fetch-retry")(global.fetch);
|
const fetchRetry = require("fetch-retry")(global.fetch);
|
||||||
const si = require("systeminformation");
|
const osUtils = require("os-utils");
|
||||||
const { readFileSync, writeFileSync, existsSync } = require("fs");
|
const { readFileSync, writeFileSync, existsSync } = require("fs");
|
||||||
|
|
||||||
// The PORT to use for the Nitro subprocess
|
// The PORT to use for the Nitro subprocess
|
||||||
@ -440,11 +440,10 @@ function spawnNitroProcess(nitroResourceProbe: any): Promise<any> {
|
|||||||
*/
|
*/
|
||||||
function getResourcesInfo(): Promise<ResourcesInfo> {
|
function getResourcesInfo(): Promise<ResourcesInfo> {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
const cpu = await si.cpu();
|
const cpu = await osUtils.cpuCount();
|
||||||
// const mem = await si.mem();
|
console.log("cpu: ", cpu);
|
||||||
|
|
||||||
const response: ResourcesInfo = {
|
const response: ResourcesInfo = {
|
||||||
numCpuPhysicalCore: cpu.physicalCores,
|
numCpuPhysicalCore: cpu,
|
||||||
memAvailable: 0,
|
memAvailable: 0,
|
||||||
};
|
};
|
||||||
resolve(response);
|
resolve(response);
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@janhq/core": "file:../../core",
|
"@janhq/core": "file:../../core",
|
||||||
"systeminformation": "^5.21.8",
|
"os-utils": "^0.0.14",
|
||||||
"ts-loader": "^9.5.0"
|
"ts-loader": "^9.5.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
@ -26,6 +26,6 @@
|
|||||||
"README.md"
|
"README.md"
|
||||||
],
|
],
|
||||||
"bundleDependencies": [
|
"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 = {
|
const response = {
|
||||||
cpu,
|
mem: {
|
||||||
mem,
|
totalMemory,
|
||||||
// gpu,
|
usedMemory,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
resolve(response);
|
resolve(response);
|
||||||
});
|
});
|
||||||
|
|
||||||
const getCurrentLoad = async () =>
|
const getCurrentLoad = () =>
|
||||||
new Promise(async (resolve) => {
|
new Promise((resolve) => {
|
||||||
const currentLoad = await si.currentLoad();
|
osUtils.cpuUsage(function(v){
|
||||||
resolve(currentLoad);
|
const cpuPercentage = v * 100;
|
||||||
|
const response = {
|
||||||
|
cpu: {
|
||||||
|
usage: cpuPercentage,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
resolve(response);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@ -32,24 +32,26 @@ export default function useGetSystemResources() {
|
|||||||
const currentLoadInfor = await monitoring?.getCurrentLoad()
|
const currentLoadInfor = await monitoring?.getCurrentLoad()
|
||||||
|
|
||||||
const ram =
|
const ram =
|
||||||
(resourceInfor?.mem?.active ?? 0) / (resourceInfor?.mem?.total ?? 1)
|
(resourceInfor?.mem?.usedMemory ?? 0) /
|
||||||
if (resourceInfor?.mem?.active) setUsedRam(resourceInfor.mem.active)
|
(resourceInfor?.mem?.totalMemory ?? 1)
|
||||||
if (resourceInfor?.mem?.total) setTotalRam(resourceInfor.mem.total)
|
if (resourceInfor?.mem?.usedMemory) setUsedRam(resourceInfor.mem.usedMemory)
|
||||||
|
if (resourceInfor?.mem?.totalMemory)
|
||||||
|
setTotalRam(resourceInfor.mem.totalMemory)
|
||||||
|
|
||||||
setRam(Math.round(ram * 100))
|
setRam(Math.round(ram * 100))
|
||||||
setCPU(Math.round(currentLoadInfor?.currentLoad ?? 0))
|
setCPU(Math.round(currentLoadInfor?.cpu?.usage ?? 0))
|
||||||
setCpuUsage(Math.round(currentLoadInfor?.currentLoad ?? 0))
|
setCpuUsage(Math.round(currentLoadInfor?.cpu?.usage ?? 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getSystemResources()
|
getSystemResources()
|
||||||
|
|
||||||
// Fetch interval - every 5s
|
// Fetch interval - every 2s
|
||||||
// TODO: Will we really need this?
|
// TODO: Will we really need this?
|
||||||
// There is a possibility that this will be removed and replaced by the process event hook?
|
// There is a possibility that this will be removed and replaced by the process event hook?
|
||||||
const intervalId = setInterval(() => {
|
const intervalId = setInterval(() => {
|
||||||
getSystemResources()
|
getSystemResources()
|
||||||
}, 5000)
|
}, 2000)
|
||||||
|
|
||||||
// clean up interval
|
// clean up interval
|
||||||
return () => clearInterval(intervalId)
|
return () => clearInterval(intervalId)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user