Comparing version 0.0.9 to 0.0.10
@@ -28,4 +28,7 @@ var dgram = require('dgram') | ||
// #### @options {Object} Aditional options | ||
// #### @options.socket {Object} Optional socket if we want to share | ||
// #### @options.socket {Object} Optional socket if we want to share | ||
// #### @options.on_error {Function} A function to execute on errors | ||
// #### @options.scope {String} define the a prefix for all stats, | ||
// e.g. with `scope` 'product1' and stat 'somestat' the key would | ||
// actually be 'product1.somestat'. | ||
// | ||
@@ -51,2 +54,17 @@ // var client = new lynx('localhost', 8125); | ||
// | ||
// Handle prefix | ||
// | ||
this.scope = options && options.scope || options && options.prefix || ''; | ||
// | ||
// groups in graphite are delimited by `.` so we need to make sure our | ||
// scope ends with `.`. If it doesn't we just add it (unless we have no | ||
// scope defined). | ||
// | ||
if(typeof this.scope === 'string' && this.scope !== '' && | ||
!/\.$/.test(this.scope)) { | ||
this.scope += '.'; | ||
} | ||
// | ||
// When a *shared* socked isn't provided, an ephemeral | ||
@@ -76,5 +94,14 @@ // socket is demand allocated. This ephemeral socket is closed | ||
this.parser.on('error', this.on_error); | ||
this.parser.on('stat', function (text, stat_obj) { | ||
var stat = {}; | ||
// | ||
// Construct a statsd value|type pair | ||
// | ||
stat[stat_obj.stat] = stat_obj.value + '|' + stat_obj.type; | ||
// | ||
// Add sample rate if one exists | ||
// | ||
if(stat_obj.sample_rate) { | ||
@@ -367,3 +394,3 @@ stat[stat_obj.stat] += '@' + stat_obj.sample_rate; | ||
send_data = all_stats.map(function construct_stat(stat) { | ||
return stat + ':' + sampled_stats[stat]; | ||
return self.scope + stat + ':' + sampled_stats[stat]; | ||
}).join('\n'); | ||
@@ -377,2 +404,3 @@ | ||
; | ||
// | ||
@@ -379,0 +407,0 @@ // Do we already have a socket object we can use? |
{ "name" : "lynx" | ||
, "description" : "Minimalistic StatsD client for Node.js programs" | ||
, "version" : "0.0.9" | ||
, "version" : "0.0.10" | ||
, "author" : "Lloyd Hilaiel" | ||
@@ -5,0 +5,0 @@ , "contributors": [ "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)" ] |
@@ -19,2 +19,10 @@ # lynx | ||
> var lynx = require('lynx'); | ||
// | ||
// Options in this instantiation include: | ||
// * `on_error` function to be executed when we have errors | ||
// * `socket` if you wish to just use a existing udp socket | ||
// * `scope` to define the a prefix for all stats, e.g. with `scope` | ||
// 'product1' and stat 'somestat' the key would actually be | ||
// 'product1.somestat' | ||
// | ||
> var metrics = new lynx('localhost', 8125); | ||
@@ -21,0 +29,0 @@ { host: 'localhost', port: 8125 } |
@@ -258,2 +258,7 @@ var path = require('path') | ||
// | ||
if(resource === 'scopes') { | ||
macros.connection.close(); | ||
macros.connection = new lynx('localhost', macros.udpServerPort, { | ||
scope: 'scope' }); | ||
} | ||
f(macros.connection); | ||
@@ -260,0 +265,0 @@ }); |
40899
24
1218
154