node-dogstatsd
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,10 +0,20 @@ | ||
'use strict'; | ||
"use strict"; | ||
var dgram = require("dgram"); | ||
var mersenne = require("./mersenne"); | ||
var mt = new mersenne.MersenneTwister19937(); | ||
var Client = function(host, port) { | ||
this.host = host; | ||
this.port = port; | ||
this.socket = require("dgram").createSocket("udp4"); | ||
var EPHEMERAL_LIFETIME_MS = 1000; | ||
var Client = function(host, port, socket) { | ||
this.host = host || "localhost"; | ||
this.port = port || 8125; | ||
// optional shared socket | ||
this.socket = socket; | ||
// when a *shared* socked isn't provided, an ephemeral | ||
// socket is demand allocated. This ephemeral socket is closed | ||
// after being idle for EPHEMERAL_LIFETIME_MS. | ||
this.ephemeral_socket = this.last_used_timer = null; | ||
}; | ||
@@ -45,21 +55,55 @@ | ||
var self = this; | ||
if (typeof(stats) === "string") { | ||
if (typeof(stats) === "string") | ||
stats = [stats]; | ||
} | ||
if (!delta) { | ||
if (!delta) | ||
delta = 1; | ||
} | ||
var data = {}; | ||
for (var i = 0; i < stats.length; i++) { | ||
for (var i = 0; i < stats.length; i++) | ||
data[stats[i]] = delta + "|c"; | ||
} | ||
self.send(data, sampleRate, tags); | ||
}; | ||
Client.prototype.send = function(data, sample_rate, tags) { | ||
// An internal function update the last time the socket was | ||
// used. This function is called when the socket is used | ||
// and causes demand allocated ephemeral sockets to be closed | ||
// after a period of inactivity. | ||
Client.prototype._update_last_used = function () { | ||
if (!this.ephemeral_socket) | ||
return; | ||
if (this.last_used_timer) | ||
clearTimeout(this.last_used_timer); | ||
var self = this; | ||
if (!sample_rate) { | ||
sample_rate = 1; | ||
this.last_used_timer = setTimeout(function() { | ||
if (self.ephemeral_socket) | ||
self.ephemeral_socket.close(); | ||
delete self.ephemeral_socket; | ||
}, EPHEMERAL_LIFETIME_MS); | ||
}; | ||
Client.prototype.send_data = function (buf) { | ||
var socket; | ||
if (!this.socket) { | ||
if (!this.ephemeral_socket) { | ||
this.ephemeral_socket = dgram.createSocket("udp4"); | ||
this.ephemeral_socket.on("error", function() {}); | ||
} | ||
socket = this.ephemeral_socket; | ||
} | ||
else { | ||
socket = this.socket; | ||
} | ||
this._update_last_used(); | ||
socket.send(buf, 0, buf.length, this.port, this.host); | ||
}; | ||
Client.prototype.send = function(data, sample_rate, tags) { | ||
if (!sample_rate) | ||
sample_rate = 1; | ||
var value; | ||
@@ -75,5 +119,4 @@ var sampled_data = {}; | ||
} | ||
else { | ||
else | ||
sampled_data = data; | ||
} | ||
@@ -83,5 +126,4 @@ if (tags && Array.isArray(tags)) { | ||
for (stat in sampled_data) { | ||
for (stat in sampled_data) | ||
sampled_data[stat] = sampled_data[stat] + "|#" + tagStr; | ||
} | ||
} | ||
@@ -91,7 +133,19 @@ | ||
var send_data = stat + ":" + sampled_data[stat]; | ||
send_data = new Buffer(send_data); | ||
this.socket.send(send_data, 0, send_data.length, self.port, self.host); | ||
this.send_data(new Buffer(send_data)); | ||
} | ||
}; | ||
Client.prototype.close = function() { | ||
if (this.socket) | ||
this.socket.close(); | ||
if (this.ephemeral_socket) | ||
this.ephemeral_socket.close(); | ||
if (this.last_used_timer) | ||
clearTimeout(this.last_used_timer); | ||
this.ephemeral_socket = | ||
this.last_used_timer = | ||
this.socket = null; | ||
}; | ||
exports.StatsD = Client; |
{ | ||
"name" : "node-dogstatsd", | ||
"description" : "node client for extended StatsD server of Datadog", | ||
"version" : "0.0.3", | ||
"version" : "0.0.4", | ||
"author" : "Young Han Lee", | ||
@@ -23,4 +23,4 @@ "repository" : { | ||
"url" : "http://github.com/joybro/node-dogstatsd/raw/master/LICENSE" | ||
} | ||
} | ||
] | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19473
367
1