npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

process-monitor

v0.3.0

Published

Monitors the CPU and memory usage for a PID or collection of PIDs.

Downloads

11

Readme

process-monitor

Build Status

Monitors the CPU and memory usage for a PID or collection of PIDs asynchronously and emits an event with a stats object which includes information about the specified PID. Allows a user-specified format string for creating a friendly status message.

Getting Started

Install the module:

npm install process-monitor

Use it in your script:

var procmon = require('process-monitor');

Monitor a single PID or multiple PIDs:

// Single PID
var single = procmon.monitor({ pid: 1, interval: 5000 }).start();

// Multiple PIDs
var multi = procmon.monitor({ pid: [1, 2, 3] }).start();

Handle the stats response - an event will be emitted for each of the specified PIDs and includes the PID:

single.on('stats', function(stats) {
  console.dir(stats); // Outputs: { pid: 1, cpu: '0.0', mem: '2248', out: '' }
})

Note: if a PID is not found, the resulting cpu and mem properties will be 0.0 and 0 respectively.

Documentation

Generated code documentation is available here and in the docs directory. This documentation is generated using docco-husky - to regenerate the documentation, run $ docco-husky lib/*.

Currently the monitor function accepts the following configuration options:

pid

The pid option may be a single process ID or an array from process IDs to monitor. The PID is also included in the stats object on when the stats event is emitted.

procmon.monitor({ pid: 1}).start();
procmon.monitor({ pid: [1, 2, 3] }).start();

interval

The rate in milliseconds at which the processes are checked and the stats event is emitted. The rate defaults to 1000 miliseconds.

procmon.monitor({ pid: 1, interval: 5000 }).start();

format

Specify a format string that will be updated in the stats object on update. Use {pid}, {cpu}, and {mem} to output a friendly message on update.

procmon.monitor({
  pid: [1, 2],
  interval: 5000,
  format: 'PID {pid} - {cpu}% CPU - {mem} memory'
}).start();

procmon.on('stats', function(stats) {
  console.log(stats.out);
});

technique

There are two supported techniques for reading process information.

procmon.monitor({
  pid: 1,
  interval: 5000,
  technique: 'ps'
}).start();
  • ps (default): Uses the ps command to find CPU and memory usage. CPU value returned from the ps command is a lifetime average and does not reflect the current usage.
  • proc: Uses information stored in the /proc files to calculate current CPU usage. Implementation comes from the node-usage module. Only supported on Linux.

Release History

  • 2013/04/23 - v0.3.0 - Added support for current CPU usage. Uses node-usage module.
  • 2012/09/28 - v0.2.0 - Added format to the configuration object which accepts a format for the output (the out property of the stats object). Uses stringformat which allows the use of {cpu}, {mem}, and {pid} in the format string.
  • 2012/09/24 - v0.1.1 - Documentation update for publishing to npm.
  • 2012/09/14 - v0.1.0 - Initial release.

License

Copyright (c) 2012 Modulus Licensed under the MIT license.