Giter VIP home page Giter VIP logo

metron's Introduction

metron

A simple whitelisted statsd passthrough.

      ,     ,
     (\____/)  Store the things
      (_oo_)  /
        (O)  /
      __||__    \)
   []/______\[] /
   / \______/ \/
  /    /__\
 (\   /____\

travis-ci status

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:

/* pseudocode for creating a statsd connection */
var statsd = require('statsd');
var statsdConnection = statsd({ })

var statsdStore = function(name, val, config){
  statsd.send(config.dataType, name, val);
}
/* end statsd pseudocode */

var config = {
  // The port to run the metron server on
  port: 8000,

  // The list of data segments to store. A segment is way to categorize
  // individual parameters.
  segments: {
    // You can specify a datastore at the segment or at the parameter level.
    dataStore: statsdStore,

    // Our first segment, `rum`.
    rum: {
      // This is a sample definition for the `pageLoadTime` parameter in the
      // `rum` segment.
      //
      // You can specify a number of options to format and filter the values
      // before they hit your data store. You can also add any arbitrary keys
      // you might want sent to your datastore or validation, such as a statsd
      // data type.
      pageLoadTime: {
        type: 'integer', // string, float, date
        min: 0,
        max: 10000,
        format: function(val){ },
        validate: function(val){ },

        // datastore: dataStoreOverride

        /* options useful for strings: */
        // length: 10,
        // truncate: 10,
        // format: function(val, config){ }

        // Example custom paramete:
        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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.