• Stars
    star
    439
  • Rank 97,023 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 13 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

node.js client for Etsy'd StatsD server

node-statsd

A node.js client for Etsy's 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.

Build Status

Installation

$ npm install node-statsd

Usage

All initialization parameters are optional.

Parameters (specified as an options hash):

  • host: The host to send stats to default: localhost
  • port: The port to send stats to default: 8125
  • prefix: What to prefix each stat name with default: ''
  • suffix: What to suffix each stat name with default: ''
  • globalize: Expose this StatsD instance globally? default: false
  • cacheDns: Cache the initial dns lookup to host default: false
  • mock: Create a mock StatsD instance, sending no stats to the server? default: false
  • global_tags: Optional tags that will be added to every metric default: []

All StatsD methods have the same API:

  • name: Stat name required
  • value: Stat value required except in increment/decrement where it defaults to 1/-1 respectively
  • sampleRate: Sends only a sample of data to StatsD default: 1
  • tags: The Array of tags to add to metrics default: []
  • 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 = require('node-statsd'),
      client = new StatsD();

  // Timing: sends a timing command with the specified milliseconds
  client.timing('response_time', 42);

  // Increment: Increments a stat by a value (default is 1)
  client.increment('my_counter');

  // Decrement: Decrements a stat by a value (default is -1)
  client.decrement('my_counter');

  // Histogram: send data for histogram stat
  client.histogram('my_histogram', 42);

  // Gauge: Gauge a stat by a specified amount
  client.gauge('my_gauge', 123.45);

  // Set: Counts unique occurrences of a stat (alias of unique)
  client.set('my_unique', 'foobar');
  client.unique('my_unique', 'foobarbaz');

  // Incrementing multiple items
  client.increment(['these', 'are', 'different', 'stats']);

  // Sampling, this will sample 25% of the time the StatsD Daemon will compensate for sampling
  client.increment('my_counter', 1, 0.25);

  // Tags, this will add user-defined tags to the data
  client.histogram('my_histogram', 42, ['foo', 'bar']);

  // Using the callback
  client.set(['foo', 'bar'], 42, function(error, bytes){
    //this only gets called once after all messages have been sent
    if(error){
      console.error('Oh noes! There was an error:', error);
    } else {
      console.log('Successfully sent', bytes, 'bytes');
    }
  });

  // Sampling, tags and callback are optional and could be used in any combination
  client.histogram('my_histogram', 42, 0.25); // 25% Sample Rate
  client.histogram('my_histogram', 42, ['tag']); // User-defined tag
  client.histogram('my_histogram', 42, next); // Callback
  client.histogram('my_histogram', 42, 0.25, ['tag']);
  client.histogram('my_histogram', 42, 0.25, next);
  client.histogram('my_histogram', 42, ['tag'], next);
  client.histogram('my_histogram', 42, 0.25, ['tag'], next);

Errors

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.

client.socket.on('error', function(error) {
  return console.error("Error in socket: ", error);
});

If you want to catch errors in sending a message then use the callback provided.

License

node-statsd is licensed under the MIT license.

More Repositories

1

pystatsd

Python implementation of the Statsd client/server
Python
357
star
2

veloci-wiki

Notational Velocity and Github wiki Integration
Perl
17
star
3

node-short

url shortener for node.js
JavaScript
15
star
4

django-copyblock

Manage website copy as a directory of markdown-formatted files. Insert files as copy into your templates.
Python
14
star
5

statsd-client

Client for Etsy's statsd server
Perl
14
star
6

TinWhistle

A URl shortener loosely based on Tantek ร‡elik's Whistle URL shortener.
Perl
6
star
7

makeitgoo

fledgling one-button deploy tool for... web applications
Python
6
star
8

sivy-emacs-toys

emacs additions, config, custom modes
Emacs Lisp
6
star
9

flask_activitypub

Playground activitypub implementation as a Flask extension
Python
5
star
10

boxpub

Personal Publishing from Dropbox.
Python
4
star
11

Salmon

A "lightweight, robust mechanism for digitally signing nearly arbitrary messages, along with a basic public key infrastructure for discovering the signing keys." An implementation of the Magic Signatures from the Salmon protocol. (See README)
Perl
4
star
12

mt-plugin-bad-robot

Bad Robot plugin for Movable Type and Melody: Selectively disallow robots from accessing blog content
3
star
13

idact-identity

identity server for idact experiments
Python
3
star
14

movable-type-plugin-debug

Adds built-in debug logging to Movable Type's Component.pm
Perl
3
star
15

mt-plugin-privatelabelfeed

Private Label Feed plugin for MovableType and Melody
Perl
2
star
16

node-oauth

Messing with oauth in node.js
JavaScript
2
star
17

python-dropbox

Fork of the Dropbox Python Client API
Python
2
star
18

monkinetic

monkinetic weblog source!
Ruby
2
star
19

mt-theme-sight

An MT port of the new Wordpress Sight template
2
star
20

whosays

random quote app for Google App Engine
2
star
21

idact-activity

identity-activity experiments
Python
1
star
22

gae-learning

GEA learnination
Python
1
star
23

goldfrog

Goldfrog, a shiny blog
Go
1
star
24

wallrazer.com

wallrazer website
Ruby
1
star
25

statsd-proxy

A HTTP proxy to Statsd
JavaScript
1
star