You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
6
6
7
7
## Getting Started
8
8
@@ -14,32 +14,70 @@ Use it in your script:
14
14
15
15
var procmon = require('process-monitor');
16
16
17
-
Monitor a single PID or mulitple PIDs:
17
+
Monitor a single PID or multiple PIDs:
18
18
19
19
// Single PID
20
20
var single = procmon.monitor({ pid: 1, interval: 5000 }).start();
21
21
22
22
// Multiple PIDs
23
23
var multi = procmon.monitor({ pid: [1, 2, 3] }).start();
24
24
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:
_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._
32
32
33
33
## 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
35
35
`docco-husky` - to regenerate the documentation, run `$ docco-husky lib/*`.
36
36
37
37
Currently the `monitor` function accepts the following configuration options:
38
38
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.
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.
41
77
42
78
## 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.
43
81
* 2012/09/24 - v0.1.1 - Documentation update for publishing to npm.
</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><spanclass="gravatar"><imgsrc="http://www.gravatar.com/avatar/e382905ab2b34219ea5ec5ca6e18fe79"/><span>Modulus <[email protected]></span></span></p><h3>Contributors</h3><p><spanclass="gravatar"><imgsrc="http://www.gravatar.com/avatar/aab639e3bbc03775ccd128a473813a96"/><span>Brandon Cannaday<[email protected]></span></span></p><p><spanclass="gravatar"><imgsrc="http://www.gravatar.com/avatar/1a1ecb880527b1fccad00224317c5cc6"/><span>Matt Hernandez<[email protected]></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><preclass="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><spanclass="gravatar"><imgsrc="http://www.gravatar.com/avatar/e382905ab2b34219ea5ec5ca6e18fe79"/><span>Modulus <[email protected]></span></span></p><h3>Contributors</h3><p><spanclass="gravatar"><imgsrc="http://www.gravatar.com/avatar/aab639e3bbc03775ccd128a473813a96"/><span>Brandon Cannaday<[email protected]></span></span></p><p><spanclass="gravatar"><imgsrc="http://www.gravatar.com/avatar/1a1ecb880527b1fccad00224317c5cc6"/><span>Matt Hernandez<[email protected]></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><preclass="code_stats">
3
+
http://cloc.sourceforge.net v 1.55 T=0.5 s (2.0 files/s, 380.0 lines/s)
<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>
<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>
44
44
45
45
<h2>Documentation</h2>
46
46
47
-
<p>Generated code documentation is available in the docs directory. This documentation is generated using
47
+
<p>Generated code documentation is available <ahref="http://eventargs.com/docs/process-monitor/">here</a> and in the docs directory. This documentation is generated using
48
48
<code>docco-husky</code> - to regenerate the documentation, run <code>$ docco-husky lib/*</code>.</p>
49
49
50
50
<p>Currently the <code>monitor</code> function accepts the following configuration options:</p>
51
51
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>
<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>
56
81
57
82
<h2>Release History</h2>
58
83
59
84
<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 <ahref="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>
0 commit comments