Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-statsd

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-statsd - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

17

lib/statsd.js

@@ -13,5 +13,6 @@ var dgram = require('dgram'),

* @option cacheDns {boolean} An optional option to only lookup the hostname -> ip address once
* @option mock {boolean} An optional boolean indicating this Client is a mock object, no stats are sent.
* @constructor
*/
var Client = function (host, port, prefix, suffix, globalize, cacheDns) {
var Client = function (host, port, prefix, suffix, globalize, cacheDns, mock) {
var options = host || {},

@@ -27,3 +28,4 @@ self = this;

globalize : globalize,
cacheDns : cacheDns
cacheDns : cacheDns,
mock : mock === true
};

@@ -37,2 +39,3 @@ }

this.socket = dgram.createSocket('udp4');
this.mock = options.mock;

@@ -173,7 +176,11 @@ if(options.cacheDns === true){

buf = new Buffer(message);
this.socket.send(buf, 0, buf.length, this.port, this.host, callback);
// Only send this stat if we're not a mock Client.
if(!this.mock) {
buf = new Buffer(message);
this.socket.send(buf, 0, buf.length, this.port, this.host, callback);
} else {
callback(null, 0);
}
};
exports.StatsD = Client;
{ "name" : "node-statsd"
, "description" : "node client for Etsy'd StatsD server"
, "version" : "0.0.5"
, "version" : "0.0.6"
, "author" : "Steve Ivy"

@@ -5,0 +5,0 @@ , "contributors": [ "Russ Bradberry <rbradberry@gmail.com>" ]

@@ -28,2 +28,3 @@ # node-statsd

* `dnsCache`: Cache the initial dns lookup to *host* `default: false`
* `mock`: Create a mock StatsD instance, sending no stats to the server? `default: false`

@@ -30,0 +31,0 @@ All StatsD methods have the same API:

@@ -25,2 +25,34 @@ var dgram = require('dgram'),

/**
* Given a StatsD method, make sure no data is sent to the server
* for this method when used on a mock Client.
*/
function assertMockClientMethod(method, finished){
var testFinished = "test finished message";
udpTest(function(message, server){
// We only expect to get our own test finished message, no stats.
assert.equal(message, testFinished);
server.close();
finished();
}, function(server){
var address = server.address(),
statsd = new StatsD(address.address, address.port, 'prefix', 'suffix', false, false,
/* mock = true */ true),
socket = dgram.createSocket("udp4"),
buf = new Buffer(testFinished);
statsd[method]('test', 1, null, function(error, bytes){
assert.ok(!error);
assert.equal(bytes, 0);
// We should call finished() here, but we have to work around
// https://github.com/joyent/node/issues/2867 on node 0.6,
// such that we don't close the socket within the `listening` event
// and pass a single message through instead.
socket.send(buf, 0, buf.length, address.port, address.address,
function(){ socket.close(); });
});
});
}
/**
* Since sampling uses random, we need to patch Math.random() to always give

@@ -37,3 +69,3 @@ * a consisten result

describe('#init', function(){
it('should set a default values when not specified', function(){
it('should set default values when not specified', function(){
var statsd = new StatsD();

@@ -44,2 +76,3 @@ assert.equal(statsd.host, 'localhost');

assert.equal(statsd.suffix, '');
assert.ok(!statsd.mock);
});

@@ -75,7 +108,7 @@

assert.equal(statsd.host, '127.0.0.1');
done()
done();
});
};
var statsd = new StatsD({host: 'localhost', cacheDns: true})
statsd = new StatsD({host: 'localhost', cacheDns: true});
});

@@ -94,6 +127,6 @@

var statsd = new StatsD({host: 'localhost'})
statsd = new StatsD({host: 'localhost'});
process.nextTick(function(){
dns.lookup = originalLookup;
done()
done();
});

@@ -114,2 +147,7 @@ });

it('should create a mock Client when mock variable is specified', function(){
var statsd = new StatsD('host', 1234, 'prefix', 'suffix', false, false, true);
assert.ok(statsd.mock);
});
it('should create a socket variable that is an instance of dgram.Socket', function(){

@@ -177,2 +215,6 @@ var statsd = new StatsD();

});
it('should send no timing stat when a mock Client is used', function(finished){
assertMockClientMethod('timing', finished);
});
});

@@ -236,2 +278,6 @@

});
it('should send no gauge stat when a mock Client is used', function(finished){
assertMockClientMethod('gauge', finished);
});
});

@@ -295,2 +341,6 @@

});
it('should send no increment stat when a mock Client is used', function(finished){
assertMockClientMethod('increment', finished);
});
});

@@ -355,2 +405,6 @@

});
it('should send no decrement stat when a mock Client is used', function(finished){
assertMockClientMethod('decrement', finished);
});
});

@@ -414,4 +468,8 @@

});
it('should send no set stat when a mock Client is used', function(finished){
assertMockClientMethod('set', finished);
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc