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:
parent
162fa48c63
commit
0a7e26d5fb
@ -17,7 +17,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@janhq/core": "file:../../core",
|
"@janhq/core": "file:../../core",
|
||||||
"os-utils": "^0.0.14",
|
"node-os-utils": "^1.3.7",
|
||||||
"ts-loader": "^9.5.0"
|
"ts-loader": "^9.5.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
@ -26,6 +26,6 @@
|
|||||||
"README.md"
|
"README.md"
|
||||||
],
|
],
|
||||||
"bundleDependencies": [
|
"bundleDependencies": [
|
||||||
"os-utils"
|
"node-os-utils"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,25 +1,25 @@
|
|||||||
const os = require("os");
|
const os = require("os");
|
||||||
const osUtils = require("os-utils");
|
const nodeOsUtils = require("node-os-utils");
|
||||||
|
|
||||||
const getResourcesInfo = () =>
|
const getResourcesInfo = () =>
|
||||||
new Promise((resolve) => {
|
new Promise((resolve) => {
|
||||||
const totalMemory = os.totalmem();
|
nodeOsUtils.mem.used()
|
||||||
const freeMemory = os.freemem();
|
.then(ramUsedInfo => {
|
||||||
const usedMemory = totalMemory - freeMemory;
|
const totalMemory = ramUsedInfo.totalMemMb * 1024 * 1024;
|
||||||
|
const usedMemory = ramUsedInfo.usedMemMb * 1024 * 1024;
|
||||||
const response = {
|
const response = {
|
||||||
mem: {
|
mem: {
|
||||||
totalMemory,
|
totalMemory,
|
||||||
usedMemory,
|
usedMemory,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
resolve(response);
|
resolve(response);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const getCurrentLoad = () =>
|
const getCurrentLoad = () =>
|
||||||
new Promise((resolve) => {
|
new Promise((resolve) => {
|
||||||
osUtils.cpuUsage(function(v){
|
nodeOsUtils.cpu.usage().then(cpuPercentage =>{
|
||||||
const cpuPercentage = v * 100;
|
|
||||||
const response = {
|
const response = {
|
||||||
cpu: {
|
cpu: {
|
||||||
usage: cpuPercentage,
|
usage: cpuPercentage,
|
||||||
|
|||||||
@ -46,12 +46,12 @@ export default function useGetSystemResources() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getSystemResources()
|
getSystemResources()
|
||||||
|
|
||||||
// Fetch interval - every 2s
|
// Fetch interval - every 0.5s
|
||||||
// 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()
|
||||||
}, 2000)
|
}, 500)
|
||||||
|
|
||||||
// clean up interval
|
// clean up interval
|
||||||
return () => clearInterval(intervalId)
|
return () => clearInterval(intervalId)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user