is there a way to find out the % cpu usage for a node.js process with the code? so that when the node.js server is running and detect the CPU is over certain%, then it will put an alert or console output.
Try looking at this code: https://github.com/last/healthjs |
|||
On *nix systems can get process stats by reading the /proc/[pid]/stat virtual file. For example this will check the CPU usage every ten seconds, and print to the console if it's over 20%. It works by checking the number of cpu ticks used by the process and comparing the value to a second measurement made one second later. The difference is the number of ticks used by the process during that second. On POSIX systems, there are 10000 ticks per second (per processor), so dividing by 10000 gives us a percentage.
|
||||
|
You can use the os module now.
This gives you the load average for the last 60seconds, 5minutes and 15minutes. This doesnt give you the cpu usage as a % though. |
|||
|
see node-usage for tracking process CPU and Memory Usage (not the system) |
|||
|
If you haven't already, try taking a look at https://nodetime.com |
|||
|