Skip to content
← Back to Community
How to see ram and cpu usage
Profile icon
[deleted]

I am making a discord.js bot, and I was wondering if I can see how much ram and cpu usage I am using. I am hosting this off of repl, with some files and such. I have tried doing

var os = require('os'); var usedMemory = os.totalmem() -os.freemem(), totalMemory = os.totalmem(); var getpercentage = ((usedMemory/totalMemory) * 100).toFixed(2) + '%' message.channel.send("Memory used in GB", (usedMemory/ Math.pow(1024, 3)).toFixed(2)) message.channel.send("Used memory" , getpercentage);

but that does not work. any help?

Answered by PattanAhmed [earned 5 cycles]
View Answer
Voters
Profile icon
ThoriqAulia
Profile icon
gamersroyal042
Profile icon
DynamicSquid
Comments
hotnewtop
Profile icon
PattanAhmed

@JohnS4 Hi,
I think this website might help you a lot.
Click here
Thanks!

Hope this helps

Profile icon
PattanAhmed

@JohnS4
Happy to help you!

Thanks!

Profile icon
[deleted]

Quick question. it worked. But it says this.
image

Are those my stats combined with other peoples, or are those my individual project stats?
@PattanAhmed

Profile icon
PattanAhmed

@JohnS4 I think combined!
Thanks!

Profile icon
WilliamPenrod

Based on your example, you're not specifying the channel to send it to. You need to set the "channel" id or use the reply function.
Eg: message.author.send(("Memory used in GB", ((usedMemory/ Math.pow(1024, 3)).toFixed(2)));
Also don't forget to add those missing semicolons :)

Profile icon
[deleted]

I dont need to specify which channel, it is in a client.on('message', async message => {}. And here is the image of what u said.
image
@WilliamPenrod

Profile icon
Coder100

why doesn't it work?

Profile icon
[deleted]

it says the text, but it says nothing after that. No errors or anything, it just leaves it blank. It worked too when i hosted it on my [email protected]

Profile icon
AmazingMech2418

I am not familiar with Discord.js, but your code to get the percentage is correct. (besides using var instead of let or const, but that's not to big of a deal... Just best-practice to prevent memory vulnerabilities) Maybe check out the Discord.js documentation?