package
Cross-platform process cpu % and memory usage of a PID
npm install pidusageGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
35.2 kB
Includes dependencies.
Cross-platform process cpu % and memory usage of a PID.
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.
var pidusage = require('pidusage')
pidusage(process.pid, function (err, stats) {
console.log(stats)
// => {
// cpu: 10.0, // percentage (from 0 to 100*vcore)
// memory: 357306368, // bytes
// ppid: 312, // PPID
// pid: 727, // PID
// ctime: 867000, // ms user + system time
// elapsed: 6650000, // ms since the start of the process
// timestamp: 864000000 // ms since epoch
// }
cb()
})
// It supports also multiple pids
pidusage([727, 1234], function (err, stats) {
console.log(stats)
// => {
// 727: {
// cpu: 10.0, // percentage (from 0 to 100*vcore)
| Property | Linux | FreeBSD | NetBSD | SunOS | macOS | Win | AIX | Alpine |
|---|---|---|---|---|---|---|---|---|
cpu | ✅ | ❓ | ❓ | ❓ | ✅ | ℹ️ | ❓ | ✅ |
memory | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |
pid | ✅ |
✅ = Working ℹ️ = Not Accurate ❓ = Should Work ❌ = Not Working
Please if your platform is not supported or if you have reported wrong readings file an issue.
By default, pidusage will use procfile parsing on most unix systems. If you want to use ps instead use the usePs option:
pidusage(pid, {usePs: true})[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. |
| [options] | object | Options object. See the table below. |
| [callback] | function | Called when the statistics are ready. If not provided a promise is returned instead. |
Setting the options programatically will override environment variables
| Param | Type | Environment variable | Default | Description |
|---|---|---|---|---|
| [usePs] | boolean | PIDUSAGE_USE_PS | false | When true uses ps instead of proc files to fetch process information |
| [useGwmi] | boolean | false | Windows only, use gwmi (PowerShell) directly without checking whether wmic is available | |
| [maxage] | number | PIDUSAGE_MAXAGE | 60000 | Max age of a process on history. |
PIDUSAGE_SILENT=1 can be used to remove every console message triggered by pidusage.
If needed this function can be used to delete all in-memory metrics and clear the event loop. This is not necessary before exiting as the interval we're registring does not hold up the event loop.
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details.
soyuka
soyuka@gmail.com
| ❓ |
| ❓ |
| ❓ |
| ✅ |
| ✅ |
| ❓ |
| ✅ |
ctime | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |
elapsed | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |
timestamp | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |