papi-stats

0.4.0 • Public • Published

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).

Readme

Keywords

Package Sidebar

Install

npm i papi-stats

Weekly Downloads

1,019

Version

0.4.0

License

MIT

Last publish

Collaborators

  • silas