metron
A simple whitelisted statsd passthrough.
, ,
(\____/) Store the things
(_oo_) /
(O) /
__||__ \)
[]/______\[] /
/ \______/ \/
/ /__\
(\ /____\
![travis-ci status](https://travis-ci.org/reddit/metron.svg)
Simple configuration-based web server. Data goes into the metron, and out to
a data store. As simple as can be.
See ./example for example usage.
The Longer Description
I needed a simple web server that I could send metrics to from the frontend (or
backend, or whatever). For example, you might want to track browser performance
data to track page load times, or you might want to store the results of
experiments in your own data center.
This allows you to write a simple javascript config file to set up a whitelist
of stats, and set up a data storage adapter for those stats. (For browser perf
data, you might just have it go to statsd; for experiments, you might use
Hive or something else.)
How to Use Metron
Create a configuration file.
If my config.js
looked like:
var statsd = require('statsd');
var statsdConnection = statsd({ })
var statsdStore = function(name, val, config){
statsd.send(config.dataType, name, val);
}
var config = {
port: 8000,
segments: {
dataStore: statsdStore,
rum: {
pageLoadTime: {
type: 'integer',
min: 0,
max: 10000,
format: function(val){ },
validate: function(val){ },
dataType: 'timer'
}
}
}
}
module.exports = config;
I could write a server.js
like:
var Metron = require('metron');
var metron = new Metron(require('./config'));
metron.start();
console.log('server started at ' + metron.get('port'));
I could then POST json data (or GET, using a ?data=<json>
querystring) to
localhost:8000
. For example:
POST localhost:8000
Content-Type: application/json
{ "rum" : { "pageLoadTime" : 600 } }
Which would then, in our example, use our statsdStore
to send data.
Notes
Metron doesn't currently deal with rate limiting, so you may want to stick an
nginx in front to handle being hammered. You're also on your own for
implementing data adapters; you may want to batch multiple stat requests from a
single request as well.
License
MIT. Copyright 2014 reddit.