All Projects → soyuka → Pidusage

soyuka / Pidusage

Licence: mit
Cross-platform process cpu % and memory usage of a PID

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Pidusage

kotary
Managing Kubernetes Quota with confidence
Stars: ✭ 85 (-76.65%)
Mutual labels:  cpu, memory
Arch
极客时间专栏《许式伟的架构课》相关的源代码:冯诺伊曼结构
Stars: ✭ 335 (-7.97%)
Mutual labels:  cpu, memory
AtomicWatch
Intel Atom C2000 series discovery tool that parses log files and returns results if a positive match is found. #nsacyber
Stars: ✭ 25 (-93.13%)
Mutual labels:  cpu, processor
Mobileperf
Android performance test
Stars: ✭ 286 (-21.43%)
Mutual labels:  cpu, memory
psutil
Cross-platform lib for process and system monitoring in Python
Stars: ✭ 8,488 (+2231.87%)
Mutual labels:  cpu, memory
doc
Get usage and health data about your Node.js process.
Stars: ✭ 17 (-95.33%)
Mutual labels:  cpu, memory
stress
Single-purpose tools to stress resources
Stars: ✭ 24 (-93.41%)
Mutual labels:  cpu, memory
FPGACosmacELF
A re-creation of a Cosmac ELF computer, Coded in SpinalHDL
Stars: ✭ 31 (-91.48%)
Mutual labels:  cpu, processor
Ybtaskscheduler
iOS 任务调度器,为 CPU 和内存减负(用于性能优化)
Stars: ✭ 270 (-25.82%)
Mutual labels:  cpu, memory
audria
audria - A Utility for Detailed Ressource Inspection of Applications
Stars: ✭ 35 (-90.38%)
Mutual labels:  cpu, memory
nodejs
Node.js in-process collectors for Instana
Stars: ✭ 66 (-81.87%)
Mutual labels:  cpu, memory
vue-adaptive-utils
Deliver empathetic experiences to your users by adapting to their capabilities
Stars: ✭ 59 (-83.79%)
Mutual labels:  cpu, memory
tree-core-cpu
A series of RISC-V soft core processor written from scratch. Now, we're using all open-source toolchain( chisel, mill, verilator, NEMU, AM and difftest framework, etc) to design and verify.
Stars: ✭ 22 (-93.96%)
Mutual labels:  cpu, processor
cpu monitor
ROS node that publishes all nodes' CPU and memory usage
Stars: ✭ 52 (-85.71%)
Mutual labels:  cpu, memory
hardware
Get CPU, Memory and Network informations of the running OS and its processes
Stars: ✭ 70 (-80.77%)
Mutual labels:  cpu, memory
cpu-memory-monitor
CPU & Memory Monitor, auto dump.
Stars: ✭ 26 (-92.86%)
Mutual labels:  cpu, memory
Forth Cpu
A Forth CPU and System on a Chip, based on the J1, written in VHDL
Stars: ✭ 244 (-32.97%)
Mutual labels:  cpu, processor
Pm2 Server Monit
Monitor server CPU / Memory / Process / Zombie Process / Disk size / Security Packages / Network Input / Network Output
Stars: ✭ 247 (-32.14%)
Mutual labels:  cpu, memory
ddcpuid
🔬 dd's x86 CPU Identification tool
Stars: ✭ 21 (-94.23%)
Mutual labels:  cpu, processor
CPU-MEM-monitor
A simple script to log Linux CPU and memory usage (using top or pidstat command) over time and output an Excel- or OpenOfficeCalc-friendly report
Stars: ✭ 41 (-88.74%)
Mutual labels:  cpu, memory

pidusage

Mac/Linux Build Status Windows Build status Code coverage npm version license

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')

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)
  //     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
  //   },
  //   1234: {
  //     cpu: 0.1,             // percentage (from 0 to 100*vcore)
  //     memory: 3846144,      // bytes
  //     ppid: 727,            // PPID
  //     pid: 1234,            // PID
  //     ctime: 0,             // ms user + system time
  //     elapsed: 20000,       // ms since the start of the process
  //     timestamp: 864000000  // ms since epoch
  //   }
  // }
})

// If no callback is given it returns a promise instead
const stats = await pidusage(process.pid)
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
// }

// Avoid using setInterval as they could overlap with asynchronous processing
function compute(cb) {
  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()
  })
}

function interval(time) {
  setTimeout(function() {
    compute(function() {
      interval(time)
    })
  }, time)
}

// Compute statistics every second:
interval(1000)

// Above example using async/await
const compute = async () => {
  const stats = await pidusage(process.pid)
  // do something
}

// Compute statistics every second:
const interval = async (time) => {
  setTimeout(async () => {
    await compute()
    interval(time)
  }, time)
}

interval(1000)

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.

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})

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 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.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].