Permalink
Browse files

Merged options in

  • Loading branch information...
jeff-minard-ck committed Jun 15, 2012
2 parents b6ee059 + cd9daa5 commit fd6c5e064dbfc0ecff1277877d5f726059e98444
Showing with 44 additions and 3 deletions.
  1. +38 −3 backends/graphite.js
  2. +6 −0 exampleConfig.js
View
@@ -10,6 +10,9 @@
*
* graphiteHost: Hostname of graphite server.
* graphitePort: Port to contact graphite server at.
+ * graphiteSimpleTimers: Record only the mean value for timers. (Default false)
+ * graphiteRecordNumStats: Record the total number of stats written. (Default true)
+ * graphiteRecordCounterTotals: Record the stats_count values for counters. (Default true)
*/
var net = require('net'),
@@ -19,6 +22,9 @@ var debug;
var flushInterval;
var graphiteHost;
var graphitePort;
+var graphiteSimpleTimers;
+var graphiteRecordNumStats;
+var graphiteRecordCounterTotals;
var graphiteStats = {};
@@ -62,13 +68,33 @@ var flush_stats = function graphite_flush(ts, metrics) {
var valuePerSecond = value / (flushInterval / 1000); // calculate "per second" rate
statString += 'stats.' + key + ' ' + valuePerSecond + ' ' + ts + "\n";
- statString += 'stats_counts.' + key + ' ' + value + ' ' + ts + "\n";
+
+ if (graphiteRecordCounterTotals) {
+ statString += 'stats_counts.' + key + ' ' + value + ' ' + ts + "\n";
+ }
numStats += 1;
}
for (key in timers) {
- if (timers[key].length > 0) {
+
+ if (timers[key].length == 0) {
+ continue;
+ }
+
+ if (graphiteSimpleTimers) {
+
+ var sum = 0;
+ for (var i in timers[key]) {
+ sum += timers[key][i];
+ }
+ var mean = sum / timers[key].length;
+
+ statString += 'stats.timers.' + key + '.mean' + ' ' + mean + ' ' + ts + "\n";
+ numStats += 1;
+
+ } else {
+
var values = timers[key].sort(function (a,b) { return a-b; });
var count = values.length;
var min = values[0];
@@ -110,6 +136,7 @@ var flush_stats = function graphite_flush(ts, metrics) {
statString += message;
numStats += 1;
+
}
}
@@ -137,7 +164,10 @@ var flush_stats = function graphite_flush(ts, metrics) {
}
}
- statString += 'statsd.numStats ' + numStats + ' ' + ts + "\n";
+ if (graphiteRecordNumStats == true) {
+ statString += 'statsd.numStats ' + numStats + ' ' + ts + "\n";
+ }
+
post_stats(statString);
};
@@ -149,9 +179,14 @@ var backend_status = function graphite_status(writeCb) {
exports.init = function graphite_init(startup_time, config, events) {
debug = config.debug;
+
graphiteHost = config.graphiteHost;
graphitePort = config.graphitePort;
+ graphiteSimpleTimers = typeof config.graphiteSimpleTimers === 'boolean' ? config.graphiteSimpleTimers : false;
+ graphiteRecordNumStats = typeof config.graphiteRecordNumStats === 'boolean' ? config.graphiteRecordNumStats : true;
+ graphiteRecordCounterTotals = typeof config.graphiteRecordCounterTotals === 'boolean' ? config.graphiteRecordCounterTotals : true;
+
graphiteStats.last_flush = startup_time;
graphiteStats.last_exception = startup_time;
View
@@ -13,6 +13,12 @@ Graphite Required Variables:
graphiteHost: hostname or IP of Graphite server
graphitePort: port of Graphite server
+Graphite Optional Settings:
+
+ graphiteSimpleTimers (boolean) (Default false) Record only the mean for timers and skip all the extra types of timer aggregations (percentiles, mins, max, etc)
+ graphiteRecordNumStats (boolean) (Default true) Record the number of stats aggregated with each update
+ graphiteRecordCounterTotals (boolean) (Default true) Record the stat_count metrics for counters
+
Optional Variables:
backends: an array of backends to load. Each backend must exist

0 comments on commit fd6c5e0

Please sign in to comment.