Permalink
Browse files

add a statsd metrics hash which is also passed to the backend

this only holds the metrics processing time for now but can be used for other
metrics which are not fit to be added to the preexisting statsd metric values.
  • Loading branch information...
1 parent bd03104 commit 2546ee6263e30b616570c7af87a931e310a76c8a @mrtazz mrtazz committed Nov 11, 2012
Showing with 14 additions and 3 deletions.
  1. +5 −3 README.md
  2. +5 −0 backends/graphite.js
  3. +4 −0 lib/process_metrics.js
View
8 README.md
@@ -51,11 +51,11 @@ The percentile threshold can be tweaked with `config.percentThreshold`.
The percentile threshold can be a single value, or a list of values, and will
generate the following list of stats for each threshold:
- stats.timers.$KEY.mean_$PCT
+ stats.timers.$KEY.mean_$PCT
stats.timers.$KEY.upper_$PCT
stats.timers.$KEY.sum_$PCT
-Where `$KEY` is the stats key you specify when sending to statsd, and `$PCT` is
+Where `$KEY` is the stats key you specify when sending to statsd, and `$PCT` is
the percentile threshold.
Gauges
@@ -274,12 +274,14 @@ metrics: {
sets: sets,
counter_rates: counter_rates,
timer_data: timer_data,
+ statsd_metrics: statsd_metrics,
pctThreshold: pctThreshold
}
```
The counter_rates and timer_data are precalculated statistics to simplify
- the creation of backends. Each backend module is passed the same set of
+ the creation of backends, the statsd_metrics hash contains metrics generated
+ by statsd itself. Each backend module is passed the same set of
statistics, so a backend module should treat the metrics as immutable
structures. StatsD will reset timers and counters after each
listener has handled the event.
View
5 backends/graphite.js
@@ -62,6 +62,7 @@ var flush_stats = function graphite_flush(ts, metrics) {
var sets = metrics.sets;
var counter_rates = metrics.counter_rates;
var timer_data = metrics.timer_data;
+ var statsd_metrics = metrics.statsd_metrics;
for (key in counters) {
statString += 'stats.' + key + ' ' + counter_rates[key] + ' ' + ts + "\n";
@@ -92,6 +93,10 @@ var flush_stats = function graphite_flush(ts, metrics) {
numStats += 1;
}
+ for (key in statsd_metrics) {
+ statString += 'stats.statsd.' + key + ' ' + statsd_metrics[key] + ' ' + ts + "\n";
+ }
+
statString += 'statsd.numStats ' + numStats + ' ' + ts + "\n";
statString += 'stats.statsd.graphiteStats.calculationtime ' + (Date.now() - starttime) + ' ' + ts + "\n";
post_stats(statString);
View
4 lib/process_metrics.js
@@ -1,7 +1,9 @@
var process_metrics = function (metrics, flushInterval, ts, flushCallback) {
+ var starttime = Date.now();
var key;
var counter_rates = {};
var timer_data = {};
+ var statsd_metrics = {};
var counters = metrics.counters;
var timers = metrics.timers;
var pctThreshold = metrics.pctThreshold;
@@ -75,9 +77,11 @@ var process_metrics = function (metrics, flushInterval, ts, flushCallback) {
}
}
+ statsd_metrics["processing_time"] = (Date.now() - starttime);
//add processed metrics to the metrics_hash
metrics.counter_rates = counter_rates;
metrics.timer_data = timer_data;
+ metrics.statsd_metrics = statsd_metrics;
flushCallback(metrics);
}

0 comments on commit 2546ee6

Please sign in to comment.