From 4c2b0a622e0b561d9cccda3479ec4b80ee5f47fe Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Tue, 3 Oct 2017 13:51:41 +0200 Subject: [PATCH] Support sending raw messages to statsd daemon Sometimes the API abstraction doesn't help much. With this functionality, the user can directly send a message across the wire. This can be useful when a statsd server supports different metric types (ie. Datadog). --- lib/statsd.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/statsd.js b/lib/statsd.js index f27383b..4ddbdba 100644 --- a/lib/statsd.js +++ b/lib/statsd.js @@ -214,7 +214,16 @@ Client.prototype.send = function (stat, value, type, sampleRate, tags, callback) if(merged_tags.length > 0){ message += '|#' + merged_tags.join(','); } + + this.sendMessage(message, callback); +}; +/** + * Sends a raw message across to statsd server + * @param message {String} The message to send + * @param callback {Function=} Callback when message is done being delivered. Optional. + */ +Client.prototype.sendMessage = function (message, callback) { // Only send this stat if we're not a mock Client. if(!this.mock) { buf = new Buffer(message); @@ -224,7 +233,7 @@ Client.prototype.send = function (stat, value, type, sampleRate, tags, callback) callback(null, 0); } } -}; +} /** * Close the underlying socket and stop listening for data on it.