process-cpu-usage

Calc the percentage cpu usage of node process

Usage no npm install needed!

<script type="module">
  import processCpuUsage from 'https://cdn.skypack.dev/process-cpu-usage';
</script>

README

node-process-cpu-usage

Aim

Get % CPU usage of current node process.

Usage

const ProcessCPULoad = require('process-cpu-usage').ProcessCPULoad;

const tracker = new ProcessCPULoad();

tracker.start((total, user, system) => {
  console.log('CPU Usage: Total: %d, User: %d, System: %d', total, user, system);
});

Have a try

# start example server
$ cd bash
$ ./benchmark-server.sh

# start wrk benchmark client
$ ./benchmark-client.sh

# see the console output of script benchmark-server.sh

# and use read-load-by-ps.sh to see the CPU usage from linux ps command
$ ./read-load-by-ps.sh