Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
InconceivableDuck committed Apr 23, 2013
2 parents a0405e5 + 0627090 commit a164194
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 58 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Node modules
node_modules

# Mac files
.DS_Store
54 changes: 46 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://secure.travis-ci.org/fiveisprime/process-monitor.png)](http://travis-ci.org/fiveisprime/process-monitor)

Monitors the CPU and memory usage for a PID or collection of PIDs.
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

Expand All @@ -14,32 +14,70 @@ Use it in your script:

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

Monitor a single PID or mulitple PIDs:
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 - a response will emitted for each of the specified PIDs and includes the PID:
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' }
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 an empty string._
_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 in the docs directory. This documentation is generated using
Generated code documentation is available [here](http://eventargs.com/docs/process-monitor/) 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` - Either a PID number or an array of PID numbers
* `interval` - Rate in milliseconds at which the processes are checked and the stats event is emitted (defaults to 1000 ms)
### 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](https://npmjs.org/package/usage) module. Only supported on Linux.

## Release History
* 2013/04/23 - v0.3.0 - Added support for current CPU usage. Uses [node-usage](https://npmjs.org/package/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](https://npmjs.org/package/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.

Expand Down
53 changes: 40 additions & 13 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<!DOCTYPE html><html><head><title>README</title><meta http-equiv="Content-Type" content="text/html" charset="UTF-8"><link rel="stylesheet" media="all" href="./docco.css"></head><body><div id="container"><div id="background"></div><div id="jump_to">Jump To &hellip;<div id="jump_wrapper"><div id="jump_page"><a href="./index.html" class="source"><span class="file_name">README</span></a><a href="./lib/process-monitor.js.html" class="source "><span class="base_path">lib / </span><span class="file_name">process-monitor.js</span></a></div></div></div><table cellpadding="0" cellspacing="0"><thead><tr><th class="docs"></th><th class="code"></th></tr></thead><tbody><tr id="section"><td class="docs"><h1><a href="https://github.com/onmodulus/process-monitor">process-monitor
</a></h1><p>Monitors the CPU and memory usage for a PID or collection of PIDs.</p><h3>Version</h3><p>0.1.0</p><h3>Author</h3><p><span class="gravatar"><img src="http://www.gravatar.com/avatar/e382905ab2b34219ea5ec5ca6e18fe79"/><span>Modulus &lt;[email protected]&gt;</span></span></p><h3>Contributors</h3><p><span class="gravatar"><img src="http://www.gravatar.com/avatar/aab639e3bbc03775ccd128a473813a96"/><span>Brandon Cannaday&lt;[email protected]&gt;</span></span></p><p><span class="gravatar"><img src="http://www.gravatar.com/avatar/1a1ecb880527b1fccad00224317c5cc6"/><span>Matt Hernandez&lt;[email protected]&gt;</span></span></p><h3>Repository</h3><p>git - git://github.com/onmodulus/process-monitor.git</p><h3>Dependencies </h3><ul><li><b>string </b><span>0.2.x</span></li></ul><p><h3>Stats</h3><pre class="code_stats">
http://cloc.sourceforge.net v 1.55 T=0.5 s (2.0 files/s, 336.0 lines/s)
</a></h1><p>Monitors the CPU and memory usage for a PID or collection of PIDs.</p><h3>Version</h3><p>0.2.0</p><h3>Author</h3><p><span class="gravatar"><img src="http://www.gravatar.com/avatar/e382905ab2b34219ea5ec5ca6e18fe79"/><span>Modulus &lt;[email protected]&gt;</span></span></p><h3>Contributors</h3><p><span class="gravatar"><img src="http://www.gravatar.com/avatar/aab639e3bbc03775ccd128a473813a96"/><span>Brandon Cannaday&lt;[email protected]&gt;</span></span></p><p><span class="gravatar"><img src="http://www.gravatar.com/avatar/1a1ecb880527b1fccad00224317c5cc6"/><span>Matt Hernandez&lt;[email protected]&gt;</span></span></p><h3>Repository</h3><p>git - git://github.com/onmodulus/process-monitor.git</p><h3>Dependencies </h3><ul><li><b>string </b><span>0.2.x</span></li><li><b>stringformat </b><span>0.0.5</span></li></ul><p><h3>Stats</h3><pre class="code_stats">
http://cloc.sourceforge.net v 1.55 T=0.5 s (2.0 files/s, 380.0 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Javascript 1 28 77 63
Javascript 1 43 81 66
-------------------------------------------------------------------------------
</pre></p></td><td id="content" class="code"><h1>process-monitor</h1>

<p><a href="http://travis-ci.org/fiveisprime/process-monitor"><img src="https://secure.travis-ci.org/fiveisprime/process-monitor.png" alt="Build Status" title="" /></a></p>

<p>Monitors the CPU and memory usage for a PID or collection of PIDs.</p>
<p>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.</p>

<h2>Getting Started</h2>

Expand All @@ -24,7 +24,7 @@ <h2>Getting Started</h2>
<pre><code>var procmon = require('process-monitor');
</code></pre>

<p>Monitor a single PID or mulitple PIDs:</p>
<p>Monitor a single PID or multiple PIDs:</p>

<pre><code>// Single PID
var single = procmon.monitor({ pid: 1, interval: 5000 }).start();
Expand All @@ -33,30 +33,57 @@ <h2>Getting Started</h2>
var multi = procmon.monitor({ pid: [1, 2, 3] }).start();
</code></pre>

<p>Handle the <code>stats</code> response - a response will emitted for each of the specified PIDs and includes the PID:</p>
<p>Handle the <code>stats</code> response - an event will be emitted for each of the specified PIDs and includes the PID:</p>

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

<p><em>Note: if a PID is not found, the resulting cpu and mem properties will be an empty string.</em></p>
<p><em>Note: if a PID is not found, the resulting cpu and mem properties will be 0.0 and 0 respectively.</em></p>

<h2>Documentation</h2>

<p>Generated code documentation is available in the docs directory. This documentation is generated using
<p>Generated code documentation is available <a href="http://eventargs.com/docs/process-monitor/">here</a> and in the docs directory. This documentation is generated using
<code>docco-husky</code> - to regenerate the documentation, run <code>$ docco-husky lib/*</code>.</p>

<p>Currently the <code>monitor</code> function accepts the following configuration options:</p>

<ul>
<li><code>pid</code> - Either a PID number or an array of PID numbers</li>
<li><code>interval</code> - Rate in milliseconds at which the processes are checked and the stats event is emitted (defaults to 1000 ms)</li>
</ul>
<h3>pid</h3>

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

<pre><code>procmon.monitor({ pid: 1}).start();
procmon.monitor({ pid: [1, 2, 3] }).start();
</code></pre>

<h3>interval</h3>

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

<pre><code>procmon.monitor({ pid: 1, interval: 5000 }).start();
</code></pre>

<h3>format</h3>

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

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

procmon.on('stats', function(stats) {
console.log(stats.out);
});
</code></pre>

<h2>Release History</h2>

<ul>
<li>2012/09/28 - v0.2.0 - Added <code>format</code> to the configuration object which accepts a format for the output (the <code>out</code> property of the <code>stats</code> object). Uses <a href="https://npmjs.org/package/stringformat">stringformat</a> which allows the use of <code>{cpu}</code>, <code>{mem}</code>, and <code>{pid}</code> in the format string.</li>
<li>2012/09/24 - v0.1.1 - Documentation update for publishing to npm.</li>
<li>2012/09/14 - v0.1.0 - Initial release.</li>
</ul>

Expand Down
Loading

0 comments on commit a164194

Please sign in to comment.