Skip to content

kevinburkeshyp/librato-node

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

librato-node

librato-node is a Node.js client for Librato Metrics (http://metrics.librato.com/)

build status npm version mit license we're hiring

Getting Started

Install

$ npm install librato-node

Setup

Once librato.start is called, a worker will send aggregated stats to Librato once every 60 seconds.

var librato = require('librato-node');
 
librato.configure({email: 'foo@example.com', token: 'ABC123'});
librato.start();

process.once('SIGINT', function() {
  librato.stop(); // stop optionally takes a callback
});

Increment

Use librato.increment to track counts in Librato. On each flush, the incremented total for that period will be sent.

var librato = require('librato-node');

librato.increment('foo');
librato.increment('foo', 2);

Measurements

You can send arbitrary measurements to Librato using librato.measure. These will be sent as gauges. For example:

var librato = require('librato-node');

librato.measure('member-count', 2001);
librato.measure('response-time', 500);

Timing

Use librato.timing to measure durations in Librato. You can pass it a synchronous function or an asynchronous function (it checks the function arity). For example:

var librato = require('librato-node');

// synchronous
librato.timing('foo', function() {
  for (var i=0; i<50000; i++) console.log(i);
});

// async without a callback
librato.timing('foo', function(done) {
  setTimeout(done, 1000);
});

// async with a callback
var workFn = function(done) {
  setTimeout(function() {
    done(null, 'foo');
  });
};
var cb = function(err, res) {
  console.log(res); // => 'foo'
};
librato.timing('foo', workFn, cb);

Express

librato-node includes Express middleware to log the request count and response times for your app. It also works in other Connect-based apps.

var express = require('express');
var librato = require('librato-node');

var app = express();
app.use(librato.middleware());

The key names the middleware uses are configurable by passing an options hash.

librato.middleware({requestCountKey: 'myRequestCount', responseTimeKey: 'myResponseTime'});

Contributing

$ git clone https://github.com/goodeggs/librato-node && cd librato-node
$ npm install
$ npm test

History

librato-node is largely based off of Librato's own librato-rack. Visit that repository if you're running Ruby or for more information on Librato Metrics in general.


License

MIT

Packages

No packages published

Languages

  • CoffeeScript 100.0%