0

I have a program that reads the following files:

cat /sys/fs/cgroup/cpu/cpuacct.usage /sys/fs/cgroup/cpu/cpu.cfs_quota_us /sys/fs/cgroup/cpu/cpu.cfs_period_us /sys/fs/cgroup/memory/memory.usage_in_bytes /sys/fs/cgroup/memory/memory.soft_limit_in_bytes /sys/fs/cgroup/memory/memory.limit_in_bytes &&grep '^\\(total_rss\\|total_cache\\) ' /sys/fs/cgroup/memory/memory.stat

On some Linux machines, it works fine. But I'm trying to make it cross-platform and I'm using Node.js. How can I get all of this info (RAM usage, CPU usage, etc) from Node in the same format as the command above?

So I basically want to know exactly what the files in the above command do, and how I can generate the same output using Node.js.

LuisAFK
  • 846
  • 4
  • 22

1 Answers1

0

You can calculate the usage using these two functions:

os.freemem()

Amount of free memory in bytes.

os.totalmem()

Total amount of memory in bytes.

Source: Node.js docs

Newbie...
  • 139
  • 2
  • 16
  • I'm already using those functions, but how do I get the info in the same format as the command I sent? – LuisAFK Mar 18 '23 at 18:31