Skip to content

Commit

Permalink
Fix bad 'this' reference in updateFromEventEmitter
Browse files Browse the repository at this point in the history
Add an example of using jmxstat.jar
  • Loading branch information
jonjlee committed Feb 8, 2011
1 parent 0bdb2f0 commit d233e9c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
47 changes: 47 additions & 0 deletions examples/graphjmx.ex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*jslint forin:true */

var assert = require('assert'),
child_process = require('child_process'),
reporting = require('../lib/reporting'),
REPORT_MANAGER = reporting.REPORT_MANAGER;

REPORT_MANAGER.setLogFile('.reporting.test-output.html');

var hostAndPort = 'localhost:9999',
refreshInterval = 2;

var report = REPORT_MANAGER.addReport('JMX'),
memory = report.getChart('Memory'),
cpu = report.getChart('CPU');

var jmx = reporting.spawnAndMonitor(
/HeapMemoryUsage.max=(.*) HeapMemoryUsage.committed=(.*) HeapMemoryUsage.used=(.*) SystemLoadAverage=([0-9\.]*)/,
['max', 'committed', 'used', 'loadavg'],
'java', [
'-jar', 'jmxstat/jmxstat.jar',
hostAndPort,
'java.lang:type=Memory[HeapMemoryUsage.max,HeapMemoryUsage.committed,HeapMemoryUsage.used]',
'java.lang:type=OperatingSystem[SystemLoadAverage]',
refreshInterval
]
),
iostat = reporting.spawnAndMonitor(
/ +[^ ]+ +[^ ]+ +[^ ]+ +([^ ]+) +([^ ]+) +[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+/,
['user', 'system'],
'iostat', [refreshInterval]
);

jmx.stderr.on('data', function (data) {
console.log(data.toString());
});

jmx.on('exit', function (code) {
if (code !== 0) { console.log('JMX monitor died with code ' + code); }
process.exit(code);
});

jmx.on('data', function(data) {
memory.put({max: data.max/1024, committed: data.committed/1024, used: data.used/1024});
});

cpu.updateFromEventEmitter(iostat, ['user', 'system']);
13 changes: 7 additions & 6 deletions lib/reporting/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ Chart.prototype = {
*/
updateFromEventEmitter: function(eventEmitter, fields, event) {
eventEmitter.on(event || 'data', function(data) {
var row = {};
fields.forEach(function(i) {
if (data[i] !== undefined) { row[i] = data[i]; }
var self = this;
eventEmitter.on(event || 'data', function(data) {
var row = {};
fields.forEach(function(i) {
if (data[i] !== undefined) { row[i] = data[i]; }
});
self.put(row);
});
this.put(row);
});
}
};

Expand Down
3 changes: 2 additions & 1 deletion nodeload.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d233e9c

Please sign in to comment.