Skip to content

Commit a164194

Browse files
Merge branch 'develop'
2 parents a0405e5 + 0627090 commit a164194

File tree

7 files changed

+226
-58
lines changed

7 files changed

+226
-58
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Node modules
2+
node_modules
3+
4+
# Mac files
5+
.DS_Store

README.md

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

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

77
## Getting Started
88

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

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

17-
Monitor a single PID or mulitple PIDs:
17+
Monitor a single PID or multiple PIDs:
1818

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

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

25-
Handle the `stats` response - a response will emitted for each of the specified PIDs and includes the PID:
25+
Handle the `stats` response - an event will be emitted for each of the specified PIDs and includes the PID:
2626

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

31-
_Note: if a PID is not found, the resulting cpu and mem properties will be an empty string._
31+
_Note: if a PID is not found, the resulting cpu and mem properties will be 0.0 and 0 respectively._
3232

3333
## Documentation
34-
Generated code documentation is available in the docs directory. This documentation is generated using
34+
Generated code documentation is available [here](http://eventargs.com/docs/process-monitor/) and in the docs directory. This documentation is generated using
3535
`docco-husky` - to regenerate the documentation, run `$ docco-husky lib/*`.
3636

3737
Currently the `monitor` function accepts the following configuration options:
3838

39-
* `pid` - Either a PID number or an array of PID numbers
40-
* `interval` - Rate in milliseconds at which the processes are checked and the stats event is emitted (defaults to 1000 ms)
39+
### pid
40+
41+
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.
42+
43+
procmon.monitor({ pid: 1}).start();
44+
procmon.monitor({ pid: [1, 2, 3] }).start();
45+
46+
### interval
47+
48+
The rate in milliseconds at which the processes are checked and the stats event is emitted. The rate defaults to 1000 miliseconds.
49+
50+
procmon.monitor({ pid: 1, interval: 5000 }).start();
51+
52+
### format
53+
54+
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.
55+
56+
procmon.monitor({
57+
pid: [1, 2],
58+
interval: 5000,
59+
format: 'PID {pid} - {cpu}% CPU - {mem} memory'
60+
}).start();
61+
62+
procmon.on('stats', function(stats) {
63+
console.log(stats.out);
64+
});
65+
66+
### technique
67+
There are two supported techniques for reading process information.
68+
69+
procmon.monitor({
70+
pid: 1,
71+
interval: 5000,
72+
technique: 'ps'
73+
}).start();
74+
75+
* `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.
76+
* `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.
4177

4278
## Release History
79+
* 2013/04/23 - v0.3.0 - Added support for current CPU usage. Uses [node-usage](https://npmjs.org/package/usage) module.
80+
* 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.
4381
* 2012/09/24 - v0.1.1 - Documentation update for publishing to npm.
4482
* 2012/09/14 - v0.1.0 - Initial release.
4583

docs/index.html

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<!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
2-
</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">
3-
http://cloc.sourceforge.net v 1.55 T=0.5 s (2.0 files/s, 336.0 lines/s)
2+
</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">
3+
http://cloc.sourceforge.net v 1.55 T=0.5 s (2.0 files/s, 380.0 lines/s)
44
-------------------------------------------------------------------------------
55
Language files blank comment code
66
-------------------------------------------------------------------------------
7-
Javascript 1 28 77 63
7+
Javascript 1 43 81 66
88
-------------------------------------------------------------------------------
99
</pre></p></td><td id="content" class="code"><h1>process-monitor</h1>
1010

1111
<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>
1212

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

1515
<h2>Getting Started</h2>
1616

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

27-
<p>Monitor a single PID or mulitple PIDs:</p>
27+
<p>Monitor a single PID or multiple PIDs:</p>
2828

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

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

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

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

4545
<h2>Documentation</h2>
4646

47-
<p>Generated code documentation is available in the docs directory. This documentation is generated using
47+
<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
4848
<code>docco-husky</code> - to regenerate the documentation, run <code>$ docco-husky lib/*</code>.</p>
4949

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

52-
<ul>
53-
<li><code>pid</code> - Either a PID number or an array of PID numbers</li>
54-
<li><code>interval</code> - Rate in milliseconds at which the processes are checked and the stats event is emitted (defaults to 1000 ms)</li>
55-
</ul>
52+
<h3>pid</h3>
53+
54+
<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>
55+
56+
<pre><code>procmon.monitor({ pid: 1}).start();
57+
procmon.monitor({ pid: [1, 2, 3] }).start();
58+
</code></pre>
59+
60+
<h3>interval</h3>
61+
62+
<p>The rate in milliseconds at which the processes are checked and the stats event is emitted. The rate defaults to 1000 miliseconds.</p>
63+
64+
<pre><code>procmon.monitor({ pid: 1, interval: 5000 }).start();
65+
</code></pre>
66+
67+
<h3>format</h3>
68+
69+
<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>
70+
71+
<pre><code>procmon.monitor({
72+
pid: [1, 2],
73+
interval: 5000,
74+
format: 'PID {pid} - {cpu}% CPU - {mem} memory'
75+
}).start();
76+
77+
procmon.on('stats', function(stats) {
78+
console.log(stats.out);
79+
});
80+
</code></pre>
5681

5782
<h2>Release History</h2>
5883

5984
<ul>
85+
<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>
86+
<li>2012/09/24 - v0.1.1 - Documentation update for publishing to npm.</li>
6087
<li>2012/09/14 - v0.1.0 - Initial release.</li>
6188
</ul>
6289

0 commit comments

Comments
 (0)