Skip to content

Commit

Permalink
Fix memory on mac included cached and swap (janhq#1298)
Browse files Browse the repository at this point in the history
* Fix memory on mac included cached and swap

* set inteval monitor to 0.5s

---------

Co-authored-by: Hien To <[email protected]>
  • Loading branch information
hiento09 and hiento09 authored Jan 2, 2024
1 parent 162fa48 commit 0a7e26d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions extensions/monitoring-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -26,6 +26,6 @@
"README.md"
],
"bundleDependencies": [
"os-utils"
"node-os-utils"
]
}
28 changes: 14 additions & 14 deletions extensions/monitoring-extension/src/module.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions web/hooks/useGetSystemResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0a7e26d

Please sign in to comment.