How to find out the % CPU usage for Node.js process?

前端 未结 6 1324
挽巷
挽巷 2021-01-31 18:59

Is there a way to find out the cpu usage in % for a node.js process via code. So that when the node.js application is running on the server and detects the CPU exceeds certain %

6条回答
  •  遇见更好的自我
    2021-01-31 19:48

    You can use the os module now.

    var os = require('os');
    var loads = os.loadavg();
    

    This gives you the load average for the last 60seconds, 5minutes and 15minutes. This doesnt give you the cpu usage as a % though.

提交回复
热议问题