Reputation:
I am using node and I have some values for memory:
var freeMemory = os.freemem();
var totalMemory = os.totalmem();
I don't know if any more values are needed.
My question is...how can I get the freeMemory in percentage?
Upvotes: 2
Views: 1141
Reputation: 5931
You have the value of free memory and the value of available memory, so it is simple as a percentage calculation:
console.log(Math.round((freeMemory * 100) / totalMemory) + '%') // => 68%
Upvotes: 1
Reputation: 1
Use os-utils library
npm install os-utils
var os = require('os-utils');
os.cpuUsage(function(v){
console.log( 'CPU Usage (%): ' + v );
});
os.cpuFree(function(v){
console.log( 'CPU Free:' + v );
});
console.log(os.freememPercentage());//gets you the free memory percentage
For more visit the docs here-https://github.com/oscmejia/os-utils
Upvotes: 1