procps

0.4.1 • Public • Published

procps build status

Node.js bindings for procps, a library that provides information about processes using the /proc filesystem, using the better maintained fork.

Supported Platforms

Unixes with a /proc directory only. Tested on arch linux and ubuntu.

Installation

npm install procps

Table of Contents generated with DocToc

Example

var procps = require('procps');
 
var proctab = procps.readproctab();
var bycommand = proctab.reduce(function (acc, p) {
  acc[p.cmd] = p;
  return acc;
}, {});
 
console.log(bycommand.node)
{ cutime: 0,
  majFlt: 0,
  vmSize: 661152,
  resident: 0,
  startCode: 4194304,
  rgroup: 'kermit',
  egid: 1000,
  pgrp: 13690,
  minFlt: 3199,
  startTime: 3344937,
  suser: 'kermit',
  fgid: 1000,
  processor: 0,
  startStack: 76310960,
  sgroup: 'kermit',
  cmajFlt: 0,
  flags: 4202496,
  rss: 2431,
  tid: 13834,
  ...
  environ:
   [ 'LC_PAPER=en_US.UTF-8',
     ...
     'npm_node_execpath=/usr/bin/node' ],
  nlwp: 2,
  kstkEsp: 76309144,
  fuser: 'kermit',
  cmdline: [ 'node', 'example/readproctab.js' ],
  sigcatch: '0000000180014202',
  utime: 2,
  vmRss: 9724,
  wchan: 4294967295,
  euid: 1000,
  sigignore: '0000000000001000',
  share: 0 }

API

Unofficial procps documentation.

So far readproctab has been implemented, but lots more to come, i.e. meminfo.

readproctab::flags

A hashtable of all readproc flags. Use these in order to fill/loose specific process properties.

Source:

readproctab::flagsFillAll

The flags used by default which cause readproc to fill all properties of each process. Use them as a starting point to turn properties off selectively, i.e.:

var flags = readproctab.flagsFillAll ^ readproctab.flags.PROC_FILLENV ^ readproctab.flags.PROC_FILLUSR;
Source:

readproctab(flags_) → {Array.<Object>}

Calls underlying readproctab and returns results with the following ajustments:

  • underscore_names are camel cased
  • Int64 values are converted to Int32 values
Parameters:
Name Type Argument Description
flags_ number <optional>

flags passed to readproc, allow filling specific process properties only instead of all of them which is the default

Source:
Returns:

information about all processes running on the system

Type
Array.<Object>

sysinfo::getdiskstat() → {Object}

Gets statistics about disks/devices and partitions on the machine.

Example DiskStats
{ disks:
[ { diskName: 'sda',
writes: 51770,
weightedMilliSpentIO: 121633,
reads: 14706,
partitions: 2,
milliWriting: 102280,
milliSpentIO: 24633,
milliReading: 19366,
mergedWrites: 131130,
mergedReads: 3164,
inprogressIO: 0,
writtenSectors: 1554100,
readsSectors: 486100 },
{ diskName: 'loop0',
...
partitions:
[ { partitionName: 'sda1',
requestedWrites: 1554100,
writes: 51693,
reads: 14553,
parentDisk: 0,
readsSectors: 483762 },
{ partitionName: 'sda2',
...
]}
Source:
Returns:

with disks array and partitions array

Type
Object

sysinfo::getPidDigits() → {number}

Returns the number of digits in PID_MAX.

PID_MAX specifies the value at which PIDs wrap around (i.e., the value in this file is one greater than the maximum PID). The default value for this file, 32768, results in the same range of PIDs as on earlier kernels.

On 32-bit platforms, 32768 is the maximum value for pid_max. On 64-bit systems, pid_max can be set to any value up to 2^22 (PID_MAX_LIMIT, approximately 4 million).

Source: /proc/sys/kernel/pid_max

Source:
Returns:

the number of digits in PID_MAX

Type
number

sysinfo::getslabinfo() → {Array.<Object>}

Returns kernel slab allocator statistics. Frequently used objects in the Linux kernel (buffer heads, inodes, dentries, * etc.) have their own cache.

For each slab cache, the cache name, the number of currently active objects, the total number of available objects, the size of each object in bytes, the number of pages with at least one active object, the total number of allocated pages, and the number of pages per slab are given.

slabinfo man page

Source: /proc/slabinfo

NOTE

Since /proc/slabinfo is only accessible to root, you need to run the process with sudo to access slabinfo. It is therefore recommended to use this only when writing a script, please NEVER run your server as root!

Source:
Returns:

each with the following properties:

  • name: cache name
  • numObjs: the total number of available objects
  • objsperslab: the number of objects per slab
  • objsize: the size of each object in bytes
  • activeObjs: the number of currently active objects
Type
Array.<Object>

sysinfo::getstat() → {Object}

Gets statistics about cpu, process and memory usage. procps.getstat used by various vmstat functions.

Includes btime therefore sysinfo.getbtime is not implemented separately.

Source:
Returns:

with the following properties:

  • cpuUse : non-nice user cpu ticks
  • cpuNic : nice user cpu ticks
  • cpuSys : system cpu ticks
  • cpuIdl : idle cpu ticks
  • cpuIow : IO-wait cpu ticks
  • cpuXxx : IRQ cpu ticks
  • cpuYyy : softirq cpu ticks
  • cpuZzz : stolen irq ticks
  • pgpgin : pages paged in
  • pgpgout : pages paged out
  • pswpin : pages swapped in
  • pswpout : pages swapped out
  • intr : interrupts
  • ctxt : CPU context switches
  • running : processes running
  • blocked : processes blocked
  • btime : boot time
  • processes : forks
Type
Object

sysinfo::loadavg() → {Array.<number>}

Returns load average figures giving the number of jobs in the run queue (state R) or waiting for disk I/O (state D) averaged over 1, 5 and 15 minutes.

They are the same as the load average numbers given by uptime(1) and other programs.

Source: /proc/loadavg

Source:
Returns:

three numbers representing loadaverages over 1, 5 and 15 minutes respectively

Type
Array.<number>

sysinfo::meminfo(unit) → {Object}

A hybrid of procps.meminfo and free.

Parameters:
Name Type Argument Description
unit string <optional>

'b'|'k'|'m'|'g' to return usage in Bytes|KB|MB|GB respectively

Source:
Returns:

with properties indicating memory usage, like mainTotal

Type
Object

sysinfo::uptime() → {Object}

Returns uptime since structured into years, months, etc. for easy logging. Very similar to uptime -s command.

Source:
Returns:

with the following properties:

  • uptime: total uptime in seconds
  • idletime: total idletime in seconds
Type
Object

sysinfo::uptimeSince() → {Object}

Returns information about since when the machine is up. The result is structured into years, months, etc. for easy logging.

Very similar to the uptime -s command.

Source:
Returns:

with the following properties:

  • year: Year - 1900
  • mon : Month [0-11]
  • mday: Day [1-31]
  • hour: Hour [0-23]
  • min : Minute [0-59]
  • sec : Second [0-60] (1 leap second)
  • yday: Day in year[0-365]
  • wday: Day of week [0-6]
Type
Object

sysinfo::uptimeString(humanReadable) → {String}

Convenience function that provides information about number and users, uptime and loadavg.

Parameters:
Name Type Description
humanReadable boolean

if true only uptime is included in human readable format, otherwise all information is included.

Source:
Returns:

with uptime information

Type
String

vminfo() → {Object}

Returns various virtual memory statistics.

Source: /proc/vmstat

Source:
Returns:

with the following properties:

  • nrDirty : dirty writable pages
  • nrWriteback : pages under writeback
  • nrPagecache : pages in pagecache -- gone in 2.5.66+ kernels
  • nrPageTablePages : pages used for pagetables
  • nrReverseMaps : includes PageDirect
  • nrMapped : mapped into pagetables
  • nrSlab : in slab
  • pgpgin : kB disk reads (same as 1st num on /proc/stat page line)
  • pgpgout : kB disk writes (same as 2nd num on /proc/stat page line)
  • pswpin : swap reads (same as 1st num on /proc/stat swap line)
  • pswpout : swap writes (same as 2nd num on /proc/stat swap line)
  • pgalloc : page allocations
  • pgfree : page freeings
  • pgactivate : pages moved inactive -> active
  • pgdeactivate : pages moved active -> inactive
  • pgfault : total faults (major+minor)
  • pgmajfault : major faults
  • pgscan : pages scanned by page reclaim
  • pgrefill : inspected by refill_inactive_zone
  • pgsteal : total pages reclaimed
  • kswapdSteal : pages reclaimed by kswapd
  • pageoutrun : times kswapd ran page reclaim
  • allocstall : times a page allocator ran direct reclaim
Type
Object

generated with docme

LICENSE

MIT

Package Sidebar

Install

npm i procps

Weekly Downloads

9

Version

0.4.1

License

MIT

Last publish

Collaborators

  • thlorenz