{"name":"pidusage","version":"1.0.3","description":"Process cpu % and memory use of a PID","main":"index.js","dependencies":{},"devDependencies":{"chai":"~3.4.1","mocha":"~2.3.4","mockery":"1.4.0"},"scripts":{"test":"mocha test/test.js --reporter min"},"repository":{"type":"git","url":"git+https://github.com/soyuka/pidusage.git"},"keywords":["pid","usage","ps","cpu","memory","proc"],"author":{"name":"soyuka"},"license":"MIT","bugs":{"url":"https://github.com/soyuka/pidusage/issues"},"homepage":"https://github.com/soyuka/pidusage","gitHead":"d3ed8aa506483fef03df6ba3760436be243314a9","_id":"pidusage@1.0.3","_shasum":"c12cb22f26a2b06625464e6463b918643b55b85c","_from":".","_npmVersion":"3.9.3","_nodeVersion":"6.2.1","_npmUser":{"name":"soyuka","email":"soyuka@gmail.com"},"dist":{"shasum":"c12cb22f26a2b06625464e6463b918643b55b85c","tarball":"http://registry-npm.ywwl.com/pidusage/download/pidusage-1.0.3.tgz","integrity":"sha512-Cc1Y9m1lf2ILmXr9qLFJDww232nmDOLV7PNBa7lnARpDjIizKnhKMyT57S+km92crfP/aXHpe1yjs/FLTyNa3g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEnqDxibDG2HFsPIb17x2YvzjfXHOuVhPWbULA5T/15HAiBs5FzUO1amSjplpql0rq6LG61F6A5vB00osTCTNvL+lw=="}],"size":8035,"noattachment":false,"key":"/pidusage/-/pidusage-1.0.3.tgz"},"maintainers":[{"name":"soyuka","email":"soyuka@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/pidusage-1.0.3.tgz_1467725927160_0.9265341404825449"},"directories":{},"readme":"# pidusage\n\n[![Lint](https://github.com/soyuka/pidusage/workflows/lint/badge.svg?branch=main)](https://github.com/soyuka/pidusage/actions?query=workflow:lint+branch:main)\n[![MacOS](https://github.com/soyuka/pidusage/workflows/test-macos/badge.svg?branch=main)](https://github.com/soyuka/pidusage/actions?query=workflow:test-macos+branch:main)\n[![Ubuntu](https://github.com/soyuka/pidusage/workflows/linux/badge.svg?branch=main)](https://github.com/soyuka/pidusage/actions?query=workflow:linux+branch:main)\n[![Windows](https://github.com/soyuka/pidusage/workflows/test-windows/badge.svg?branch=main)](https://github.com/soyuka/pidusage/actions?query=workflow:test-windows+branch:main)\n[![Alpine](https://github.com/soyuka/pidusage/workflows/test-alpine/badge.svg?branch=main)](https://github.com/soyuka/pidusage/actions?query=workflow:test-alpine+branch:main)\n[![Code coverage](https://img.shields.io/codecov/c/github/soyuka/pidusage/master.svg)](https://codecov.io/gh/soyuka/pidusage)\n[![npm version](https://img.shields.io/npm/v/pidusage.svg)](https://www.npmjs.com/package/pidusage)\n[![license](https://img.shields.io/github/license/soyuka/pidusage.svg)](https://github.com/soyuka/pidusage/tree/master/license)\n\nCross-platform process cpu % and memory usage of a PID.\n\n## Synopsis\n\nIdeas from https://github.com/arunoda/node-usage but with no C-bindings.\n\nPlease note that if you need to check a Node.JS script process cpu and memory usage, you can use [`process.cpuUsage`][node:cpuUsage] and [`process.memoryUsage`][node:memUsage] 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.\n\n\n## Usage\n\n```js\nvar pidusage = require('pidusage')\n\npidusage(process.pid, function (err, stats) {\n  console.log(stats)\n  // => {\n  //   cpu: 10.0,            // percentage (from 0 to 100*vcore)\n  //   memory: 357306368,    // bytes\n  //   ppid: 312,            // PPID\n  //   pid: 727,             // PID\n  //   ctime: 867000,        // ms user + system time\n  //   elapsed: 6650000,     // ms since the start of the process\n  //   timestamp: 864000000  // ms since epoch\n  // }\n  cb()\n})\n\n// It supports also multiple pids\npidusage([727, 1234], function (err, stats) {\n  console.log(stats)\n  // => {\n  //   727: {\n  //     cpu: 10.0,            // percentage (from 0 to 100*vcore)\n  //     memory: 357306368,    // bytes\n  //     ppid: 312,            // PPID\n  //     pid: 727,             // PID\n  //     ctime: 867000,        // ms user + system time\n  //     elapsed: 6650000,     // ms since the start of the process\n  //     timestamp: 864000000  // ms since epoch\n  //   },\n  //   1234: {\n  //     cpu: 0.1,             // percentage (from 0 to 100*vcore)\n  //     memory: 3846144,      // bytes\n  //     ppid: 727,            // PPID\n  //     pid: 1234,            // PID\n  //     ctime: 0,             // ms user + system time\n  //     elapsed: 20000,       // ms since the start of the process\n  //     timestamp: 864000000  // ms since epoch\n  //   }\n  // }\n})\n\n// If no callback is given it returns a promise instead\nconst stats = await pidusage(process.pid)\nconsole.log(stats)\n// => {\n//   cpu: 10.0,            // percentage (from 0 to 100*vcore)\n//   memory: 357306368,    // bytes\n//   ppid: 312,            // PPID\n//   pid: 727,             // PID\n//   ctime: 867000,        // ms user + system time\n//   elapsed: 6650000,     // ms since the start of the process\n//   timestamp: 864000000  // ms since epoch\n// }\n\n// Avoid using setInterval as they could overlap with asynchronous processing\nfunction compute(cb) {\n  pidusage(process.pid, function (err, stats) {\n    console.log(stats)\n    // => {\n    //   cpu: 10.0,            // percentage (from 0 to 100*vcore)\n    //   memory: 357306368,    // bytes\n    //   ppid: 312,            // PPID\n    //   pid: 727,             // PID\n    //   ctime: 867000,        // ms user + system time\n    //   elapsed: 6650000,     // ms since the start of the process\n    //   timestamp: 864000000  // ms since epoch\n    // }\n    cb()\n  })\n}\n\nfunction interval(time) {\n  setTimeout(function() {\n    compute(function() {\n      interval(time)\n    })\n  }, time)\n}\n\n// Compute statistics every second:\ninterval(1000)\n\n// Above example using async/await\nconst compute = async () => {\n  const stats = await pidusage(process.pid)\n  // do something\n}\n\n// Compute statistics every second:\nconst interval = async (time) => {\n  setTimeout(async () => {\n    await compute()\n    interval(time)\n  }, time)\n}\n\ninterval(1000)\n```\n\n## Compatibility\n\n| Property | Linux | FreeBSD | NetBSD | SunOS | macOS | Win | AIX | Alpine\n| ---         | --- | --- | --- | --- | --- | --- | --- | --- |\n| `cpu`       | ✅ | ❓ | ❓ | ❓ | ✅ | ℹ️ | ❓ | ✅ |\n| `memory`    | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |\n| `pid`       | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |\n| `ctime`     | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |\n| `elapsed`   | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |\n| `timestamp` | ✅ | ❓ | ❓ | ❓ | ✅ | ✅ | ❓ | ✅ |\n\n✅ = Working\nℹ️ = Not Accurate\n❓ = Should Work\n❌ = Not Working\n\nPlease if your platform is not supported or if you have reported wrong readings\n[file an issue][new issue].\n\nBy default, pidusage will use `procfile` parsing on most unix systems. If you want to use `ps` instead use the `usePs` option:\n\n```\npidusage(pid, {usePs: true})\n```\n\n## API\n\n<a name=\"pidusage\"></a>\n\n### pidusage(pids, [options = {}], [callback]) ⇒ <code>[Promise.&lt;Object&gt;]</code>\nGet pid informations.\n\n**Kind**: global function\n**Returns**: <code>Promise.&lt;Object&gt;</code> - Only when the callback is not provided.\n**Access**: public\n\n| Param | Type | Description |\n| --- | --- | --- |\n| pids | <code>Number</code> \\| <code>Array.&lt;Number&gt;</code> \\| <code>String</code> \\| <code>Array.&lt;String&gt;</code> | A pid or a list of pids. |\n| [options] | <code>object</code> | Options object. See the table below. |\n| [callback] | <code>function</code> | Called when the statistics are ready. If not provided a promise is returned instead. |\n\n### options\n\nSetting the options programatically will override environment variables\n\n| Param | Type | Environment variable | Default | Description |\n| --- | --- | --- | --- | --- |\n| [usePs] | <code>boolean</code> | `PIDUSAGE_USE_PS`| `false` | When true uses `ps` instead of proc files to fetch process information |\n| [maxage] | <code>number</code> | `PIDUSAGE_MAXAGE`| `60000` | Max age of a process on history. |\n\n`PIDUSAGE_SILENT=1` can be used to remove every console message triggered by pidusage.\n\n### pidusage.clear()\n\nIf 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.\n\n## Related\n- [pidusage-tree][gh:pidusage-tree] -\nCompute a pidusage tree\n\n## Authors\n- **Antoine Bluchet** - [soyuka][github:soyuka]\n- **Simone Primarosa** - [simonepri][github:simonepri]\n\nSee also the list of [contributors][contributors] who participated in this project.\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE][license] file for details.\n\n<!-- Links -->\n[new issue]: https://github.com/soyuka/pidusage/issues/new\n[license]: https://github.com/soyuka/pidusage/tree/master/LICENSE\n[contributors]: https://github.com/soyuka/pidusage/contributors\n\n[github:soyuka]: https://github.com/soyuka\n[github:simonepri]: https://github.com/simonepri\n\n[gh:pidusage-tree]: https://github.com/soyuka/pidusage-tree\n\n[node:cpuUsage]: https://nodejs.org/api/process.html#process_process_cpuusage_previousvalue\n[node:memUsage]: https://nodejs.org/api/process.html#process_process_memoryusage\n","publish_time":1467725929327,"_cnpm_publish_time":1467725929327,"dist-tags":{"latest":"4.1.0"}}