-
Notifications
You must be signed in to change notification settings - Fork 0
/
dispatcher.js
81 lines (64 loc) · 1.99 KB
/
dispatcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var EventEmitter = require('events').EventEmitter;
var async = require('async');
var Lynx = require('lynx');
var util = require('util');
function DefaultDispatcher(options) {
if (!(this instanceof DefaultDispatcher)) {
return new DefaultDispatcher(options);
}
EventEmitter.call(this);
this.options = options || {};
this.options.name = this.options.name || 'indy';
this.options.env = this.options.env || process.env.NODE_ENV || 'development';
this.lynxOptions = this.options.lynx || {};
this.metrics = new Lynx();
}
util.inherits(DefaultDispatcher, EventEmitter);
DefaultDispatcher.prototype.dispatch = function (obj, done) {
var self = this;
async.eachLimit(Object.keys(obj), 2, function iterator(fn, cb) {
setImmediate(DefaultDispatcher.prototype[fn].bind(self, obj[fn]));
cb();
}, function cb() {
// we are done.
if (done) {
return done();
}
});
};
DefaultDispatcher.prototype.gccount = function (c) {
this.metrics.gauge('v8.gc.count', c);
};
DefaultDispatcher.prototype.memrss = function (c) {
this.metrics.gauge('os.mem.rss', c);
};
DefaultDispatcher.prototype.memfree = function (c) {
this.metrics.gauge('os.mem.free', c);
};
DefaultDispatcher.prototype.memtotal = function (c) {
this.metrics.gauge('os.mem.total', c);
};
// V8 Heap Total
DefaultDispatcher.prototype.memheaptotal = function (c) {
this.metrics.gauge('v8.mem.total', c);
};
// V8 Heap Used
DefaultDispatcher.prototype.memheapused = function (c) {
this.metrics.gauge('v8.mem.used', c);
};
DefaultDispatcher.prototype.cpus = function () {
// noop for now.
};
DefaultDispatcher.prototype.loadavg5 = function (c) {
this.metrics.gauge('os.load.5', c);
};
DefaultDispatcher.prototype.loadavg10 = function (c) {
this.metrics.gauge('os.load.10', c);
};
DefaultDispatcher.prototype.loadavg15 = function (c) {
this.metrics.gauge('os.load.15', c);
};
DefaultDispatcher.prototype.delay = function (c) {
this.metrics.gauge('node.loopDelay', c);
};
module.exports = DefaultDispatcher;