How to Fetch MongoDB CPU usage and Disk utilization using Node.js or mongosh
Welcome to the MongoDB Community @Santosh_Salvaji !
Metrics like CPU usage and disk utilisation come from the host environment MongoDB processes are running in, so you will have to look into npm
packages or external tools you can invoke.
For example:
- https://www.npmjs.com/package/usage (CPU usage)
- https://www.npmjs.com/package/procfs-stats (process stats on Linux)
I can’t vouch for how well these packages work, but they might be helpful starting points.
If you happen to be using MongoDB Atlas, it surfaces many available metrics via UI (including historical charts) as well as the Atlas Administration API. The Atlas control plane collects host resource metrics including CPU, disk, memory, and network utilisation as well as MongoDB metrics such as connections, replication, and operation execution time.
For more relevant suggestions on monitoring process resources via Node.js, I suggest searching or asking on StackOverflow: Newest 'node.js' Questions - Stack Overflow.
Regards,
Stennie
Hi @Stennie_X
How to get the status of CPU usage and Disk utilisation through query/command for the cluster running on Mongodb Atlas.
I just want to make sure that CPU & Disk utilisation are under threshold before hitting Query/Command.