0.4.0 • Published 9 years ago

papi-stats v0.4.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

Papi Stats Build Status

Add basic stats support to Papi clients.

Options

  • count (Function<String, Number>): a function that increments a counter by a given amount
  • timing (Function<String, Number>): a function that records timing data in milliseconds

Example

var lynx = require('lynx');
var papi = require('papi');

var metrics = lynx('127.0.0.1', 8125, { scope: 'prefix' });

var client = new papi.Client({
  name: 'github',
  baseUrl: 'https://api.github.com',
  timeout: 10000,
});

client._plugin(require('papi-stats'), {
  count: metrics.increment.bind(metrics),
  timing: metrics.timing.bind(metrics),
});

client._get(
  {
    name: 'gists',
    path: '/users/silas/gists',
  },
  function(ctx, next) {
    if (ctx.err && ctx.err.isTimeout && !ctx._retried) {
      ctx._retried = true;
      return ctx.retry();
    }

    next();
  },
  function(err) {
    if (err) throw err;
  }
);

This could produce metrics like the following:

// responses
prefix.github.gists.200:773|ms
prefix.github.gists.401:421|ms

// non-responses
prefix.github.gists.abort:5003|ms
prefix.github.gists.timeout:10001|ms
prefix.github.gists.error:3|ms

// ctx.retry called in middleware
prefix.github.gists.retry:1|c

License

This work is licensed under the MIT License (see the LICENSE file).

0.4.0

9 years ago

0.3.0

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago