pidusage
Cross-platform process cpu % and memory usage of a PID.
Synopsis
Ideas from https://github.com/arunoda/node-usage but with no C-bindings.
Please note that if you need to check a Node.JS script process cpu and memory usage, you can use process.cpuUsage
and process.memoryUsage
since node v6.1.0. This script remain useful when you have no control over the remote script, or if the process is not a Node.JS process.
Usage
var pidusage = require('pidusage')
setInterval(function () {
pidusage(process.pid, function (err, stats) {
console.log(stats)
})
}, 1000)
pidusage([727, 1234], function (err, stats) {
console.log(stats)
})
const stats = await pidusage(process.pid)
console.log(stats)
Compatibility
Property | Linux | FreeBSD | NetBSD | SunOS | macOS | Win | AIX | Alpine |
---|
cpu | ✅ | ❓ | ❓ | ❓ | ✅ | ℹ️ | ❓ | ✅ |
memory | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |
pid | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |
ctime | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |
elapsed | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |
timestamp | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |
✅ = Working
ℹ️ = Not Accurate
❓ = Should Work
❌ = Not Working
Please if your platform is not supported or if you have reported wrong readings
file an issue.
API
pidusage(pids, [options = {}], [callback]) ⇒ [Promise.<Object>]
Get pid informations.
Kind: global function
Returns: Promise.<Object>
- Only when the callback is not provided.
Access: public
Param | Type | Description |
---|
pids | Number | Array.<Number> | String | Array.<String> | A pid or a list of pids. |
[callback] | function | Called when the statistics are ready. If not provided a promise is returned instead. |
pidusage.clear()
If needed this function can be used to clear the event loop. Indeed, we're registering an interval to free up the in-memory metrics. By calling this, it will clear this interval and all delete all in-memory data.
Related
Authors
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details.