
Security News
Software Engineering Daily Podcast: Feross on AI, Open Source, and Supply Chain Risk
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.
process-monitor
Advanced tools
Monitors the CPU and memory usage for a PID or collection of PIDs asynchronously and emits an event with a stats object which includes information about the specified PID. Allows a user-specified format string for creating a friendly status message.
Install the module:
npm install process-monitor
Use it in your script:
var procmon = require('process-monitor');
Monitor a single PID or multiple PIDs:
// Single PID
var single = procmon.monitor({ pid: 1, interval: 5000 }).start();
// Multiple PIDs
var multi = procmon.monitor({ pid: [1, 2, 3] }).start();
Handle the stats response - an event will be emitted for each of the specified PIDs and includes the PID:
single.on('stats', function(stats) {
console.dir(stats); // Outputs: { pid: 1, cpu: '0.0', mem: '2248', out: '' }
})
Note: if a PID is not found, the resulting cpu and mem properties will be 0.0 and 0 respectively.
Generated code documentation is available here and in the docs directory. This documentation is generated using
docco-husky - to regenerate the documentation, run $ docco-husky lib/*.
Currently the monitor function accepts the following configuration options:
The pid option may be a single process ID or an array from process IDs to monitor. The PID is also included in the stats object on when the stats event is emitted.
procmon.monitor({ pid: 1}).start();
procmon.monitor({ pid: [1, 2, 3] }).start();
The rate in milliseconds at which the processes are checked and the stats event is emitted. The rate defaults to 1000 miliseconds.
procmon.monitor({ pid: 1, interval: 5000 }).start();
Specify a format string that will be updated in the stats object on update. Use {pid}, {cpu}, and {mem} to output a friendly message on update.
procmon.monitor({
pid: [1, 2],
interval: 5000,
format: 'PID {pid} - {cpu}% CPU - {mem} memory'
}).start();
procmon.on('stats', function(stats) {
console.log(stats.out);
});
There are two supported techniques for reading process information.
procmon.monitor({
pid: 1,
interval: 5000,
technique: 'ps'
}).start();
ps (default): Uses the ps command to find CPU and memory usage. CPU value returned from the ps command is a lifetime average and does not reflect the current usage.proc: Uses information stored in the /proc files to calculate current CPU usage. Implementation comes from the node-usage module. Only supported on Linux.format to the configuration object which accepts a format for the output (the out property of the stats object). Uses stringformat which allows the use of {cpu}, {mem}, and {pid} in the format string.Copyright (c) 2012 Modulus Licensed under the MIT license.
FAQs
Monitors the CPU and memory usage for a PID or collection of PIDs.
We found that process-monitor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.

Security News
Rust’s crates.io team is advancing an RFC to add a Security tab that surfaces RustSec vulnerability and unsoundness advisories directly on crate pages.