Get Express Package CPU, RAM and Disk to display for my Discord Bot


I’m trying to make a bot info command which will display the project’s cpu ram and disk space. How could I get this information?

Container Stats
Container Stats Inaccurate

Hi @Fyrlex!

You can read these files:


For the values you see in the Status pane, memory usage is the total_rss line from/sys/fs/cgroup/memory/memory.stat minus Node’s process.memoryUsage().rss. Disk space comes from the check() method from the NPM package diskusage.

The percentages we display in the status bar are calculations over sliding averages of historical data, and we tweak these a little periodically to provide better info. You’re unlikely to be able to achieve an exact match for those values at any given point.

Hope this helps!

Os.totalmem() glitch
"The app exceeded the memory limit." even though it didn't, according to the container stats
"The app exceeded the memory limit." even though it didn't, according to the container stats

RAM Usage: process.memoryUsage().heapUsed / 1024 / 1024;

You can get most of the things from memoryUsage() method, it returns:

  rss: 1000,
  heapTotal: 1000,
  heapUsed: 1000,
  external: 1000


Note that that only reports on the current process and heap usage, so it’s only a portion of the full memory usage within the project.


What about for disk and cpu usage?


Is there something else you’re looking for that wasn’t in my initial reply?


I didn’t completely understand what you had written. I was looking for something like what @chroventer had posted.

What I do need is the maximum CPU (for max) and was wondering what the equation would be for it. Bolt stated above how to get the ram but it’s different for the CPU.

Currently I have this:

let cpu = Math.round(process.cpuUsage().system)
let cpupercent = Math.round((cpu * max) / 1000) / 10;

let ram = Math.round(process.memoryUsage().heapUsed / 1024 / 1024 * 10) / 10;
let rampercent = Math.round((ram / 512) * 1000) / 10;


Here’s a function to get memory usage fairly accurately:

function getMemoryUsage() {
  let total_rss = require('fs').readFileSync("/sys/fs/cgroup/memory/memory.stat", "utf8").split("\n").filter(l => l.startsWith("total_rss"))[0].split(" ")[1]; 
  return Math.round( Number(total_rss) / 1e6 ) - 60;

Explained here.