Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

silas/node-papi-stats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Add basic stats support to Papi clients

Resources

License

Stars

Watchers

Forks

Packages

No packages published