node-statsd
Advanced tools
Comparing version 0.0.7 to 0.1.0
@@ -56,7 +56,8 @@ var dgram = require('dgram'), | ||
* @param time {Number} The time in milliseconds to send | ||
* @param sampleRate {Number} The Number of times to sample (0 to 1) | ||
* @param callback {Function} Callback when message is done being delivered. Optional. | ||
* @param sampleRate {Number=} The Number of times to sample (0 to 1). Optional. | ||
* @param tags {Array=} The Array of tags to add to metrics. Optional. | ||
* @param callback {Function=} Callback when message is done being delivered. Optional. | ||
*/ | ||
Client.prototype.timing = function (stat, time, sampleRate, callback) { | ||
this.sendAll(stat, time, 'ms', sampleRate, callback); | ||
Client.prototype.timing = function (stat, time, sampleRate, tags, callback) { | ||
this.sendAll(stat, time, 'ms', sampleRate, tags, callback); | ||
}; | ||
@@ -68,7 +69,8 @@ | ||
* @param value The value to send | ||
* @param sampleRate {Number} The Number of times to sample (0 to 1) | ||
* @param callback {Function} Callback when message is done being delivered. Optional. | ||
* @param sampleRate {Number=} The Number of times to sample (0 to 1). Optional. | ||
* @param tags {Array=} The Array of tags to add to metrics. Optional. | ||
* @param callback {Function=} Callback when message is done being delivered. Optional. | ||
*/ | ||
Client.prototype.increment = function (stat, value, sampleRate, callback) { | ||
this.sendAll(stat, value || 1, 'c', sampleRate, callback); | ||
Client.prototype.increment = function (stat, value, sampleRate, tags, callback) { | ||
this.sendAll(stat, value || 1, 'c', sampleRate, tags, callback); | ||
}; | ||
@@ -80,18 +82,33 @@ | ||
* @param value The value to send | ||
* @param sampleRate {Number} The Number of times to sample (0 to 1) | ||
* @param callback {Function} Callback when message is done being delivered. Optional. | ||
* @param sampleRate {Number=} The Number of times to sample (0 to 1). Optional. | ||
* @param tags {Array=} The Array of tags to add to metrics. Optional. | ||
* @param callback {Function=} Callback when message is done being delivered. Optional. | ||
*/ | ||
Client.prototype.decrement = function (stat, value, sampleRate, callback) { | ||
this.sendAll(stat, -value || -1, 'c', sampleRate, callback); | ||
Client.prototype.decrement = function (stat, value, sampleRate, tags, callback) { | ||
this.sendAll(stat, -value || -1, 'c', sampleRate, tags, callback); | ||
}; | ||
/** | ||
* Represents the histogram stat | ||
* @param stat {String|Array} The stat(s) to send | ||
* @param value The value to send | ||
* @param sampleRate {Number=} The Number of times to sample (0 to 1). Optional. | ||
* @param tags {Array=} The Array of tags to add to metrics. Optional. | ||
* @param callback {Function=} Callback when message is done being delivered. Optional. | ||
*/ | ||
Client.prototype.histogram = function (stat, value, sampleRate, tags, callback) { | ||
this.sendAll(stat, value, 'h', sampleRate, tags, callback); | ||
}; | ||
/** | ||
* Gauges a stat by a specified amount | ||
* @param stat {String|Array} The stat(s) to send | ||
* @param value The value to send | ||
* @param sampleRate {Number} The Number of times to sample (0 to 1) | ||
* @param callback {Function} Callback when message is done being delivered. Optional. | ||
* @param sampleRate {Number=} The Number of times to sample (0 to 1). Optional. | ||
* @param tags {Array=} The Array of tags to add to metrics. Optional. | ||
* @param callback {Function=} Callback when message is done being delivered. Optional. | ||
*/ | ||
Client.prototype.gauge = function (stat, value, sampleRate, callback) { | ||
this.sendAll(stat, value, 'g', sampleRate, callback); | ||
Client.prototype.gauge = function (stat, value, sampleRate, tags, callback) { | ||
this.sendAll(stat, value, 'g', sampleRate, tags, callback); | ||
}; | ||
@@ -103,8 +120,9 @@ | ||
* @param value The value to send | ||
* @param sampleRate {Number} The Number of times to sample (0 to 1) | ||
* @param callback {Function} Callback when message is done being delivered. Optional. | ||
* @param sampleRate {Number=} The Number of times to sample (0 to 1). Optional. | ||
* @param tags {Array=} The Array of tags to add to metrics. Optional. | ||
* @param callback {Function=} Callback when message is done being delivered. Optional. | ||
*/ | ||
Client.prototype.unique = | ||
Client.prototype.set = function (stat, value, sampleRate, callback) { | ||
this.sendAll(stat, value, 's', sampleRate, callback); | ||
Client.prototype.set = function (stat, value, sampleRate, tags, callback) { | ||
this.sendAll(stat, value, 's', sampleRate, tags, callback); | ||
}; | ||
@@ -116,6 +134,7 @@ | ||
* @param value The value to send | ||
* @param sampleRate {Number} The Number of times to sample (0 to 1) | ||
* @param callback {Function} Callback when message is done being delivered. Optional. | ||
* @param sampleRate {Number=} The Number of times to sample (0 to 1). Optional. | ||
* @param tags {Array=} The Array of tags to add to metrics. Optional. | ||
* @param callback {Function=} Callback when message is done being delivered. Optional. | ||
*/ | ||
Client.prototype.sendAll = function(stat, value, type, sampleRate, callback){ | ||
Client.prototype.sendAll = function(stat, value, type, sampleRate, tags, callback){ | ||
var completed = 0, | ||
@@ -126,2 +145,13 @@ calledback = false, | ||
if(sampleRate && typeof sampleRate !== 'number'){ | ||
callback = tags; | ||
tags = sampleRate; | ||
sampleRate = undefined; | ||
} | ||
if(tags && !Array.isArray(tags)){ | ||
callback = tags; | ||
tags = undefined; | ||
} | ||
/** | ||
@@ -151,6 +181,6 @@ * Gets called once for each callback, when all callbacks return we will | ||
stat.forEach(function(item){ | ||
self.send(item, value, type, sampleRate, onSend); | ||
self.send(item, value, type, sampleRate, tags, onSend); | ||
}); | ||
} else { | ||
this.send(stat, value, type, sampleRate, callback); | ||
this.send(stat, value, type, sampleRate, tags, callback); | ||
} | ||
@@ -165,5 +195,6 @@ }; | ||
* @param sampleRate {Number} The Number of times to sample (0 to 1) | ||
* @param callback {Function} Callback when message is done being delivered. Optional. | ||
* @param tags {Array} The Array of tags to add to metrics | ||
* @param callback {Function=} Callback when message is done being delivered. Optional. | ||
*/ | ||
Client.prototype.send = function (stat, value, type, sampleRate, callback) { | ||
Client.prototype.send = function (stat, value, type, sampleRate, tags, callback) { | ||
var message = this.prefix + stat + this.suffix + ':' + value + '|' + type, | ||
@@ -181,2 +212,6 @@ buf; | ||
if(tags && Array.isArray(tags)){ | ||
message += '|#' + tags.join(','); | ||
} | ||
// Only send this stat if we're not a mock Client. | ||
@@ -193,2 +228,10 @@ if(!this.mock) { | ||
/** | ||
* Close the underlying socket and stop listening for data on it. | ||
*/ | ||
Client.prototype.close = function(){ | ||
this.socket.close(); | ||
} | ||
exports = module.exports = Client; | ||
exports.StatsD = Client; |
{ "name" : "node-statsd" | ||
, "description" : "node client for Etsy'd StatsD server" | ||
, "version" : "0.0.7" | ||
, "version" : "0.1.0" | ||
, "author" : "Steve Ivy" | ||
@@ -14,3 +14,3 @@ , "contributors": [ "Russ Bradberry <rbradberry@gmail.com>" ] | ||
, "scripts": { | ||
"test": "node ./node_modules/mocha/bin/mocha -R spec" | ||
"test": "mocha -R spec" | ||
} | ||
@@ -17,0 +17,0 @@ , "dependencies" : {} |
@@ -27,3 +27,3 @@ # node-statsd | ||
* `globalize`: Expose this StatsD instance globally? `default: false` | ||
* `dnsCache`: Cache the initial dns lookup to *host* `default: false` | ||
* `cacheDns`: Cache the initial dns lookup to *host* `default: false` | ||
* `mock`: Create a mock StatsD instance, sending no stats to the server? `default: false` | ||
@@ -35,2 +35,3 @@ | ||
* `sampleRate`: Sends only a sample of data to StatsD `default: 1` | ||
* `tags`: The Array of tags to add to metrics `default: []` | ||
* `callback`: The callback to execute once the metric has been sent | ||
@@ -41,3 +42,3 @@ | ||
```javascript | ||
var StatsD = require('node-statsd').StatsD, | ||
var StatsD = require('node-statsd'), | ||
client = new StatsD(); | ||
@@ -54,2 +55,5 @@ | ||
// Histogram: send data for histogram stat | ||
client.histogram('my_histogram', 42); | ||
// Gauge: Gauge a stat by a specified amount | ||
@@ -68,4 +72,7 @@ client.gauge('my_gauge', 123.45); | ||
// Tags, this will add user-defined tags to the data | ||
client.histogram('my_histogram', 42, ['foo', 'bar']); | ||
// Using the callback | ||
client.set(['foo', 'bar'], 42, null, function(error, bytes){ | ||
client.set(['foo', 'bar'], 42, function(error, bytes){ | ||
//this only gets called once after all messages have been sent | ||
@@ -78,2 +85,11 @@ if(error){ | ||
}); | ||
// Sampling, tags and callback are optional and could be used in any combination | ||
client.histogram('my_histogram', 42, 0.25); // 25% Sample Rate | ||
client.histogram('my_histogram', 42, ['tag']); // User-defined tag | ||
client.histogram('my_histogram', 42, next); // Callback | ||
client.histogram('my_histogram', 42, 0.25, ['tag']); | ||
client.histogram('my_histogram', 42, 0.25, next); | ||
client.histogram('my_histogram', 42, ['tag'], next); | ||
client.histogram('my_histogram', 42, 0.25, ['tag'], next); | ||
``` | ||
@@ -80,0 +96,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
107
3
13348
7
202