Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i check the current usage of ram with Node.js? (Discord.js Bot)

I want to make a command called _ram it should display the current usage of the bots ram. I already tried these things:

${client.performance.memory} //(Says memory is not defined)
${window.performance.memory} //(Window is not defined)

Is there a working way how to display it?

like image 761
SchdowNVIDIA Avatar asked Oct 15 '25 22:10

SchdowNVIDIA


2 Answers

If you want to know how much memory your Node.js process is using, you can query:

process.memoryUsage().heapUsed / 1024 / 1024;

It will output the memory used by your process in bytes. It won't show the real memory used by Node.js, as in that case you also need to take into account Node.js garbage collector.

like image 97
Arman P. Avatar answered Oct 18 '25 13:10

Arman P.


var os = require('os');

var usedMemory = os.totalmem() -os.freemem(), totalMemory = os.totalmem();

var  getpercentage = 
  ((usedMemory/totalMemory) * 100).toFixed(2) + '%'

console.log("Memory used in GB", (usedMemory/ Math.pow(1024, 3)).toFixed(2))
console.log("Used memory" , getpercentage);
like image 42
Sisir Das Avatar answered Oct 18 '25 12:10

Sisir Das



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!