statsd.js 838 Bytes
Newer Older
1 2
var tap = require('tap');

Alan Szlosek's avatar
Alan Szlosek committed
3 4 5 6 7
var Harbinger = require('../index');

var server = new Harbinger.Input.StatsD();
var udp = require('dgram').createSocket('udp4');
udp.unref();
8

Alan Szlosek's avatar
Alan Szlosek committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
tap.test('statsd.basic', function(test) {
	var message = "application.module.request.count:1|c\n";
	var out = {
		metric: 'application.module.request.count',
		value: 1,
		type: 'c',
		sampleRate: null,
		remoteAddress: '127.0.0.1'
	};
	var cb = function(err, metric, value, type, sampleRate, remoteAddress) {
		test.equal(metric, out.metric);
		test.equal(value, out.value);
		test.equal(type, out.type);
		test.equal(sampleRate, out.sampleRate);
		test.equal(remoteAddress, out.remoteAddress);
		test.end();
25

Alan Szlosek's avatar
Alan Szlosek committed
26 27
		server.close();
	};
28

Alan Szlosek's avatar
Alan Szlosek committed
29 30 31
	test.plan(5);
	server.callback(cb);
	server.bind(8125, '127.0.0.1');
32

Alan Szlosek's avatar
Alan Szlosek committed
33
	udp.send(message, 0, message.length, 8125, '127.0.0.1');
34
});