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 <hien@jan.ai>
This commit is contained in:
hiento09 2024-01-03 02:09:17 +07:00 committed by GitHub
parent 162fa48c63
commit 0a7e26d5fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 18 deletions

View File

@ -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"
]
}

View File

@ -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,

View File

@ -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)