npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

metron

v0.3.0

Published

simple whitelisted statsd passthrough.

Downloads

12

Readme

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.