I have a NodeJS application that spawns processes on a server with 24 cores. As a rule, I do not spawn more than one process per core (for a total of 24 processes at most). I would like to know the CPU usage of the core where each process is spawn. Is it possible to investigate something like this? I know I can use os.cpus()
, but this returns a more general info on all the CPUs in the machine rather than the one where the process I'm querying is working on.
Is it possible to do something like this with what we have in NodeJS? I wouldn't like to rely on executing (heavy) bash scripts from NodeJS to know something like that.
Try node-usage for tracking CPU using the PID
You can use node-usage like below
var spawn = require('child_process').spawn;
var usage = require('usage');
var ffmpeg = spawn('ffmpeg');
usage.lookup(ffmpeg.pid, function(err, usageInfo) {
console.log(usageInfo); // { cpu: 2.4, memory: 100065280 }
});
Of course I could be wrong, but I'm not sure there is an API for worker-process CPU usage, but you can get per core for all cores: http://nodejs.org/api/os.html#os_os_cpus
On another note: For such power, you might want to consider checking that you have access to all of the system's memory. V8 limits to a default that requires re-compiling in order to have "deeper-pockets' for memory access.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With