node package manager


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


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


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

var profiler = require('statsd-profiler');

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, 
  transformKeyfunction(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

profiler.increment(key, [transformKeyArgs]);

Alias : count

profiler.decrement(key, [transformKeyArgs]);

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]);
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");
profiler.timing(key, time, [transformKeyArgs]);
profiler.timeStart(key, [timeID], [transformKeyArgs]);

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

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 :


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, ...]);


  profiler.transformKey = function (keyserverID) {
    return serverID + '.' + key;
  profiler.increment('test', "server1");
  //will send 
  statsd.increment("server1.test", 1);