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

librato-node

v5.0.6

Published

A node.js client for Librato Metrics (http://metrics.librato.com/)

Downloads

2,307

Readme

librato-node

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

build status npm version mit license

Getting Started

Install

yarn add 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: '[email protected]', token: 'ABC123'});
librato.start();

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

// Don't forget to specify an error handler, otherwise errors will be thrown
librato.on('error', function(err) {
  console.error(err);
});

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');                     // increment by 1
librato.increment('foo', 2);                  // increment by 2
librato.increment('foo', 2, {source: 'bar'}); // custom source

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);
librato.measure('foo', 250, {source: 'bar'}); // custom source

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);
librato.timing('foo', workFn, {source: 'bar'}, cb); // all timing calls also accept a custom source

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'});

Advanced

By default the librato-node worker publishes data every 60 seconds. Configure this value by passing a period argument to the configure hash.

var librato = require('librato-node');
librato.configure({email: '[email protected]', token: 'ABC123', period: 5000})

Request Options

You can pass additional options for the HTTP POST to Librato using the requestOptions parameter. See request/request for a complete list of options. For example, to configure a timeout:

var librato = require('librato-node');
librato.configure({email: '[email protected]', token: 'ABC123', requestOptions: {timeout: 250}})

By default librato-node will retry up to 3 times on connection failures and 5xx responses using an exponential backoff strategy with a 100ms base. These defaults can be overridden using the requestOptions paramter. See requestretry for a list of options. For example, to limit to a single attempt:

var librato = require('librato-node');
librato.configure({email: '[email protected]', token: 'ABC123', requestOptions: {maxAttempts: 1}})

Contributing

Please follow our Code of Conduct when contributing to this project.

yarn install
yarn test

Deploying a new version

This module is automatically deployed when a version tag bump is detected by travis. Remember to update the changelog!

yarn version

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