metromatic
v0.2.0
Published
Listen events on an object and report metrics to StatsD
Downloads
4
Readme
metromatic
Report metrics based on events generated by a given event emitter. Supports StatsD, Cloudwatch & custom backends.
Installation
Install using npm
npm install metromatic
Usage
var Metromatic = require('metromatic');
const backends = [
{
type: 'statsd',
host: 'localhost',
port: 8125
},
{
type: 'cloudwatch'
region: 'us-west-1',
groupName: 'MyService'
dimensions: { environment: NODE_ENV },
accessKeyId: AWS_CLOUDWATCH_KEY_ID,
secretAccessKey: AWS_CLOUDWATCH_ACCESS_KEY,
},
{
type: 'custom',
send: (type, name, data) => {
// handle metric storage
},
}
];
Metromatic.instrument(myEventEmitter, {
backends: backends,
metrics: [{
name: 'request_time',
type: 'timing', // timing or gauge currently supported
eventStart: 'request',
eventStop: 'response'
}, {
name: 'gauge_foo',
type: 'gauge',
eventGauge: 'hey'
}]
});
Eventually, timings and gauges metrics will be sent when myEventEmitter
emits the request
and response
events (for timing) or hey
event (for gauge).
If you just want to stop listening the object:
Metromatic.restore(myEventEmitter);
To keep track of multiple timings of the same event pass any id string as a parameter when emitting the events to differentiate them.
Running tests
Run the tests using
npm test
Contributing
At the moment supports timing
and gauges
metric types. You're more than welcome to express some code love in a Pull Request to make it even more awesome.
Also, if you feel like something is quite not right or want to suggest something, leave us an open issue.
Future enhancements
- Add more metric types