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

felix-metrics

v0.0.9

Published

This is an alternative port of Coda Hale's metrics library.

Downloads

10

Readme

felix-metrics

Build Status

This is an alternative port of Coda Hale's metrics library.

I created this despite the existing metrics port for node.js because I wanted to fully understand the underlaying Math and algorithms.

Install

This is not ready for you yet

Usage

Step 1: Add metrics to your code. For example, lets track the requests/sec of a http server:

var metrics    = require('felix-metrics');
var collection = new metrics.Collection('http');
var http       = require('http');

var rps = collection.meter('requestsPerSecond');
http.createServer(function(req, res) {
  meter.mark();
  res.end('Thanks');
}).listen(3000);

Step 2: Show the collected metrics (more advanced examples follow later):

setInterval(function() {
  console.log(collection.toJSON());
}, 1000);

This will output something like this every second:

{ requestsPerSecond:
   { mean: 1710.2180279856818,
     count: 10511,
     '1MinuteRate': 168.08263156623656,
     '5MinuteRate': 34.74630977619571,
     '15MinuteRate': 11.646507524106095 } }

Step 3: Aggregate the data into your backend of choice. I recommend graphite.

Metrics

The following metrics are available (both standalone and on the Collection API):

Gauge

Values that can be read instantly. Example:

var gauge = new metrics.Gauge({read: function() {
  return process.memoryUsage().rss;
});

There is currently no callback support for Gauges because otherwise it would be very difficult to report the metrics inside a collection within a regular interval.

Options:

  • read A function that returns the current value of the Gauge.

Methods:

None.

Counter

Things that increment or decrement. Example:

var activeUploads = new metrics.Counter();
http.createServer(function(req, res) {
  activeUploads.inc();
  req.on('end', function() {
    activeUploads.dec();
  });
});

Options:

  • count An initial count for the counter. Defaults to 0.

Methods:

  • inc(n) Increment the counter by n. Defaults to 1.
  • dec(n) Decrement the counter by n. Defaults to 1.

Meter

Things that are measured as events / interval. Example:

var meter = new metrics.Meter();
http.createServer(function(req, res) {
  meter.mark();
});

Options:

  • rateUnit The rate unit. Defaults to 1000 (1 sec).
  • tickInterval The interval in which the averages are updated. Defaults to 5000 (5 sec).

Methods:

  • mark(n) Register n events as having just occured. Defaults to `1.

Histogram

Things that are measured as distributions of scalars. Example:

var histogram = new metrics.Histogram();
http.createServer(function(req, res) {
  if (req.headers['content-length']) {
    histogram.update(parseInt(req.headers['content-length'], 10));
  }
});

Options:

  • sample The sample resevoir to use. Defaults to an ExponentiallyDecayingSample.

Methods:

  • update(value, timestamp) Pushes value into the sample. timestamp defaults to Date.now().

Timers

Timers are a combination of Meters and Histograms. They measure the rate as well as distribution of scalar events. Since they are frequently used for tracking how long certain things take, they expose an API for that:

var timer = new metrics.Timer();
http.createServer(function(req, res) {
  var stopwatch = timer.start();
  req.on('end', function() {
    stopwatch.end();
  });
});

But you can also use them as generic histograms that also track the rate of events:

var timer = new metrics.Timer();
http.createServer(function(req, res) {
  if (req.headers['content-length']) {
    timer.update(parseInt(req.headers['content-length'], 10));
  }
});

Options:

  • meter The internal meter to use. Defaults to a new Meter.
  • histogram The internal histogram to use. Defaults to a new Histogram.

Methods:

  • start() Returns a Stopwatch.
  • update(value) Updates the internal histogram with value and marks one event on the internal meter.

Todo

  • Implement a graphite reporter and feature it in the usage section.

License

This module is licensed under the MIT license.