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

yodlr-metrics

v2.0.0

Published

Backend agnostic metric library that pulls config from env/etcd

Downloads

15

Readme

Yodlr Metrics Library

The goal of this library is to provide a consistent API for sending metrics from our NodeJS services.

This library exposes a constructor which provides the following metric API calls:

  • count
  • increment
  • decrement
  • timing
  • timer
  • gauge
  • set

Using this library

Construction

Staticaly define host/port and prefixes

var opts = {
  prefix: 'services.myapp', //optional
  statsd: {
    prefix: 'account-uuid', // optional
    host: '10.1.1.5',
    port: 8125
  }
  on_error: function errorHandler(err) { // if not defined, will emit 'error' instead
    console.log(err);
  }
}

Pull host/port and prefix from etcd.

If the values change, yodlr-metrics will dynamically reconfigure how it sends data. You don't need to modify you code at all.

If insufficient data is provided in etcd, yodlr-metrics will emit an error which you should capture and probably log.

var opts = {
  etcdHost: '172.17.42.1', // default, optional
  etcdPort: 4001, // default, optional
  prefix: 'services.myapp', // optional
  statsd: {
    prefix_etcd: '/services/statsd/prefix', // optional
    hostEtcd: '/services/statsd/host',
    portEtcd: '/services/statsd/port'
  }
}

Once you've decided on your configuration, you can construct a metrics object like this:

var YodlrMetrics = require('yodlr-metrics');

var opts = {
  prefix: 'services.myapp',
  statsd: {
    prefix: 'account-uuid',
    host: '10.1.1.5',
    port: 8125
  }
}

var metric = new YodlrMetrics(opts);
metric.on('error', function metricError(err) {
  console.log('Uh oh, error in yodlr-metrics', err);
})

Count

Increases or decreased a counter by the provider number.

metric.count('users.new', 5); // increments counter by 5

Increment

Increases a counter by 1

metric.increment('users.new'); // increments counter by 1

Decrement

Decreases a counter by 1

metric.decrement('users.new'); // increments counter by 1

Timing

Sends a timing metric in ms

metric.timing('user.ping_latency', 50); // sends timing metric of 50ms

Timer

Variation on the timing metric which provides a timing object with a Stop() function

var timer = metric.createTimer('user.ping_latency');
setTimeout(function() {
  timer.stop(); // sends timing metric from when object was created
}, 50);

Gauge

Sets a currently configured gauge to this new value

metric.gauge('users.current_connected', 500); // sets gauge to 500

Set

Used to count unique occurrences of events between flushes, using a Set to store all occurring events.

If a method is called multiple times with the same value in the same sample period, that value will only be counted once.

metric.set('users.active', 'Jared');
metric.set('users.active', 'Tom');
metric.set('users.active', 'Jared'); //