StatsD backend to emit stats over socket.io
JavaScript
Switch branches/tags
Nothing to show
Latest commit e58139c May 13, 2015 @timsavery timsavery Merge pull request #6 from Chatham/revert-5-revert-3-feature/socket.i…
…o-1.0.x

Upgrade to socket.io 1.0.x
Permalink
Failed to load latest commit information.
lib
test nevermind May 13, 2015
.gitignore Updating dot files May 18, 2012
.travis.yml Updating for node 0.10 Mar 16, 2013
LICENSE
README.md
package.json version bump May 13, 2015

README.md

statsd-socket.io Build Status

StatsD backend to emit stats over socket.io. This backend allows you to subscribe to individual stats, groups of stats, or all stats and handle them in real time.

Installation

There are a few ways to install statsd-socket.io to be used as a StatsD backend. You can add it to the StatsD package.json and run npm install.

The simplest way to install the module is to run:

  $ npm install statsd-socket.io

Requirements

Configuration

To add this backend to the StatsD daemon, simply add the following settings to the StatsD configuration file:

{
  socketPort: 8000,
  backends: ['statsd-socket.io']
}

If you want to keep the graphite backend installed, you need to include './backends/graphite' in the backends configuration.

Usage

var socket = require('socket.io-client').connect('http://localhost:8000');
socket.on('connect', function () {
  socket.emit('subscribe', 'all');
  socket.emit('subscribe', 'timers');
  socket.emit('subscribe', 'gauges.server1.cpu');
  socket.emit('subscribe', 'gauges.*.cpu');
});

// Retrieve all stats
socket.on('all', function (data) {
  console.log('ALL:' + data);
});

// Retrieve a groups of stats
socket.on('timers', function (data) {
  console.log(JSON.stringify(data));
});

// Retrieve a single stat
socket.on('gauges.server1.cpu', function (data) {
  console.log('Server1 CPU:' + data);
});

// Supports wildcards
socket.on('gauges.*.cpu', function (data) {
  for (var server in data.gauges) {
    console.log(server + ' CPU:' + data.gauges[server]['cpu']);
  }
});

This example shows using socket.io on the server side but can just as easily be implemented on the client side. See the socket.io documentation for more information.

Tests

To run the tests:

npm test