Permalink
Browse files

Merge branch 'raw' into rawmerge

Fixed conflicts, added patches for the "raw" type.

Conflicts:
	README.md
	stats.js
  • Loading branch information...
2 parents 41258bb + 7b8428c commit 29a73cc481fdaff678964f66bc516a3e6efd167e Peter C. Norton committed May 2, 2012
Showing with 46 additions and 0 deletions.
  1. +14 −0 README.md
  2. +32 −0 stats.js
View
@@ -64,6 +64,20 @@ There are additional config variables available for debugging:
For more information, check the `exampleConfig.js`.
+Averaging
+--------
+
+ load_5min:2.3|a
+
+Tells StatsD that the "load" average keys should be averaged before being reported.
+
+Raw Data
+--------
+
+ population:45344|r
+
+Will buffer a set of commands to send to carbon without any preprocessing. (As the major point of StatsD is to serve as an aggregator, be careful with this metric. Try to use counts, timers, and averages when you can instead of pushing lots of raw data to carbon. However, to keep reporting interfaces consistent, this is useful.)
+
Guts
----
View
@@ -7,6 +7,8 @@ var dgram = require('dgram')
var keyCounter = {};
var counters = {};
var timers = {};
+var raws = [];
+var averages = {};
var gauges = {};
var debugInt, flushInt, keyFlushInt, server, mgmtServer;
var startup_time = Math.round(new Date().getTime() / 1000);
@@ -35,6 +37,8 @@ config.configFile(process.argv[2], function (config, oldConfig) {
debugInt = setInterval(function () {
util.log("Counters:\n" + util.inspect(counters) +
"\nTimers:\n" + util.inspect(timers) +
+ "\nRaws:\n" + sys.inspect(raws) +
+ "\nAverages:\n" + sys.inspect(averages) +
"\nGauges:\n" + util.inspect(gauges));
}, config.debugInterval || 10000);
}
@@ -96,6 +100,13 @@ config.configFile(process.argv[2], function (config, oldConfig) {
timers[key].push(Number(fields[0] || 0));
} else if (fields[1].trim() == "g") {
gauges[key] = Number(fields[0] || 0);
+ } else if (fields[1].trim() == "r") {
+ raws.push([key, Number(fields[0] || 0), Math.round(new Date().getTime()/1000)]);
+ } else if (fields[1].trim() == "a") {
+ if (! averages[key]) {
+ averages[key] = [];
+ }
+ averages[key].push(Number(fields[0] || 0));
} else {
if (fields[2] && fields[2].match(/^@([\d\.]+)/)) {
sampleRate = Number(fields[2].match(/^@([\d\.]+)/)[1]);
@@ -235,6 +246,27 @@ config.configFile(process.argv[2], function (config, oldConfig) {
numStats += 1;
}
+ for (idx in raws) {
+ statString += 'stats.' + raws[idx][0] + ' ' + raws[idx][1] + ' ' + raws[idx][2] + "\n";
+ numStats += 1;
+ }
+ raws = [];
+
+ for (key in averages) {
+ var vals = averages[key],
+ valCount = averages[key].length,
+ valTotal = 0;
+ if (vals.length >= 1) {
+ for (idx in vals) {
+ valTotal += vals[idx];
+ }
+ var averageVal = valTotal / valCount;
+ averages[key] = [];
+ statString += 'stats.' + key + ' ' + averageVal + ' ' + ts + "\n";
+ numStats += 1;
+ }
+ }
+
for (key in timers) {
if (timers[key].length > 0) {
var values = timers[key].sort(function (a,b) { return a-b; });

0 comments on commit 29a73cc

Please sign in to comment.