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

statsd-profiler

v0.2.12

Published

It's a `node-statsd` library for people for whom clean code is important.

Downloads

5

Readme

node-statsd-profiler

A node-statsd fork with helpers for timing, key aliases, dynamic keys.

#initialization

Initialization has to be done only once. So you can use your statsd module globally.

var profiler = require('statsd-profiler');
profiler.init(options);

Options and defaults:

{
  host: undefined, // ip:port of the statsd server
  aliases: {}, // key aliases, see `Key aliases`
  defaultSampleRate: 1, // statsd sample rate, 1/10th of the time,
  transformKey: function(key) {return key}, // so that you can easily add dynamic prefix, suffixes
  cleanTimer: 5000 // When to cancel timeStart() requests that did not met a timeEnd()? In ms.
}

#same function as statsd

##increment

profiler.increment(key, [transformKeyArgs]);

Alias : count ##decrement

profiler.decrement(key, [transformKeyArgs]);

##gauge Note : with gauge, during the interval, only the last value is sent to graphite. The last value is sent to graphite even if no new values as been received. Ideal for queue size...

profiler.gauge(key, val, [transformKeyArgs]);

##count or set or unique

profiler.count(key, val, [transformKeyArgs]);
profiler.set(key, val, [transformKeyArgs]);
profiler.unique(key, val, [transformKeyArgs]);

Counts the unique occurences of events between flushes, using a Set to store all occuring events.

Example submission in a single flush interval, that would result in a count of 3:

profiler.set("unique_urls", "/foo");
profiler.set("unique_urls", "/bar");
profiler.set("unique_urls", "/baz");
profiler.set("unique_urls", "/foo");
profiler.set("unique_urls", "/foo");

##timing

profiler.timing(key, time, [transformKeyArgs]);

##timeStart

profiler.timeStart(key, [timeID], [transformKeyArgs]);

You can specify timeID if key is used for multiple measures concurrently.

##timeEnd

profiler.timeEnd(key, [timeID], [transformKeyArgs]);

You can specify timeID if key is used for multiple measures concurrently.

#Key aliases

With key aliases you can easily set complex keys and sample rate alias a cool name. You can create an config for each metric : with a key, a measure type and a sample rate. Each parameter is optional.

For instance, in conf object.

{
  "htmlParseTiming" : {
    "key"  : "engine.optimization.html.parse.timing",
    "sample_rate" : 0.3
  },
  "htmlParseCount" : {
    "type" : "increment",
    "key"  : "engine.optimization.html.parse.count",
    "sample_rate" : 0.9
  }
}

And after, in you code, you can simply write :

  profiler.count(htmlParseCount);
  profiler.timeStart(htmlParseTiming);
  htmlParsing();
  profiler.timeEnd(htmlParseTiming);

and the actual call to statsd will be

  statsd.increment("engine.optimization.html.parse.count", 0.9);
  statsd.timing("engine.optimization.html.parse.timing", computedTime, 0.3);

#transformKey : dynamically compute the key

Often, we want add a prefix or a suffix to our keys like the hostname, the server id... You can do that with the function transformKey.

function transformKey(key, [args1 , args2, ...]);

Example:

  profiler.transformKey = function (key, serverID) {
    return serverID + '.' + key;
  });

  profiler.increment('test', "server1");

  //will send
  statsd.increment("server1.test", 1);
};