node_stat_tracker
v0.4.3
Published
A generic stat tracker
Downloads
3
Readme
Node Stat Tracker
A generic stat tracker for NodeJS that can support many instances and different reporting backends.
Tested for NodeJS: 4+
Usage
var dummy_backend = {
counts: {},
gauges: {},
timings: {},
count: function(key, num) {
this.counts[key] += num;
},
gauge: function(key, amount) {
this.gauges[key] = amount;
},
timings: function(key, time) {
if (!this.timings[key]) {this.timings[key] = []}
this.timings[key].push(time);
}
}
var tracker = new StatTracker.Tracker({});
function track_this() {
var profiler = tracker.profiler('profile_scope');
... Some computation ...
tracker.count('step1_num_runs', 1, ["sometag"]);
profiler.tick('first_step');
... Some computation ...
tracker.count('step2_num_runs', 1);
profiler.end();
}
Backend Interface
A backend is a JavaScript prototype that implements the following:
function Backend(config) {}
Backend.prototype.count = function(metric, value, tags) {};
Backend.prototype.time = function(metric, value, tags) {};
Backend.prototype.gauge = function(metric, value, tags) {};
module.exports = Backend;
The initialization config
is provided by StatTracker backend_config
property.
Default Backends
Node Stat Tracker
comes with two backends:
statsd_backend
: Usesnode-statsd
for sending StatsD packets.logger_backend
: Logs the values usingbunyan
or config provided logger.