node client for Etsy'd StatsD server
This client will let you fire stats at your StatsD server from a node.js application.
node-statsd Runs and is tested on Node 0.6+ on all *nix platforms and 0.8+ on all platforms including Windows.
$ npm install node-statsd
All initialization parameters are optional.
Parameters (specified as an options hash):
host: The host to send stats to
port: The port to send stats to
prefix: What to prefix each stat name with
suffix: What to suffix each stat name with
globalize: Expose this StatsD instance globally?
cacheDns: Cache the initial dns lookup to host
mock: Create a mock StatsD instance, sending no stats to the server?
global_tags: Optional tags that will be added to every metric
All StatsD methods have the same API:
name: Stat name
value: Stat value
required except in increment/decrement where it defaults to 1/-1 respectively
sampleRate: Sends only a sample of data to StatsD
tags: The Array of tags to add to metrics
callback: The callback to execute once the metric has been sent
If an array is specified as the
name parameter each item in that array will be sent along with the specified value.
var StatsD =client = ;// Timing: sends a timing command with the specified millisecondsclient;// Increment: Increments a stat by a value (default is 1)client;// Decrement: Decrements a stat by a value (default is -1)client;// Histogram: send data for histogram statclient;// Gauge: Gauge a stat by a specified amountclient;// Set: Counts unique occurrences of a stat (alias of unique)client;client;// Incrementing multiple itemsclient;// Sampling, this will sample 25% of the time the StatsD Daemon will compensate for samplingclient;// Tags, this will add user-defined tags to the dataclient;// Using the callbackclient;// Sampling, tags and callback are optional and could be used in any combinationclient; // 25% Sample Rateclient; // User-defined tagclient; // Callbackclient;client;client;client;
In the event that there is a socket error,
node-statsd will allow this error to bubble up. If you would like to catch the errors, just attach a listener to the socket property on the instance.
If you want to catch errors in sending a message then use the callback provided.
node-statsd is licensed under the MIT license.