gmetric

Ganglia gmetric submission for node.js

npm install gmetric
4 downloads in the last day
45 downloads in the last week
101 downloads in the last month

node-gmetric build status

Gmetric packet submission for node.js

Sending metrics

Unspoofed

var Gmetric = require('gmetric');

var gmetric = new Gmetric();
var metric = {
  hostname: 'awesomehost.mydomain.com',
  group: 'testgroup',
  units: 'widgets/sec',
  slope: 'positive',

  name: 'bestmetric',
  value: 10,
  type: 'int32'
};

gmetric.send('127.0.0.1', 8649, metric);

Spoofed

var Gmetric = require('gmetric');

var gmetric = new Gmetric();
var metric = {
  hostname: '192.168.20.15:awesomehost.mydomain.com',
  group: 'testgroup',
  spoof: true,
  units: 'widgets/sec',
  slope: 'positive',

  name: 'bestmetric',
  value: 10,
  type: 'int32'
};

gmetric.send('127.0.0.1', 8649, metric);

Receiving and unpacking metrics

var util = require('util'),
    dgram = require('dgram'),
    server = dgram.createSocket('udp4');

var Gmetric = require('gmetric'),
    gmetric = new Gmetric();

server.on('message', function(msg, rinfo) {
  var msg_type = msg.readInt32BE(0);
  if(msg_type === 128){
    var meta = gmetric.unpack(msg);
    console.log('Received Meta Packet:');
    console.log(util.inspect(meta) + "\n");
  } else if (msg_type === 133){
    var data = gmetric.unpack(msg);
    console.log('Received Data Packet:');
    console.log(util.inspect(data) + "\n");
  }
});

server.on('listening', function(){
  console.log('Gmetric server listening...');
});

server.bind(8649);
npm loves you