Skip to content

Commit

Permalink
added sum to all metrics and mean to the total - also changed the way…
Browse files Browse the repository at this point in the history
… we calculate these metrics by using a cumulative sum as it is more efficient for multiple percentile thresholds
  • Loading branch information
Steve Mardenfeld committed Jun 14, 2012
1 parent 4e4ed79 commit ffacf28
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions backends/graphite.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ var flush_stats = function graphite_flush(ts, metrics) {
var min = values[0];
var max = values[count - 1];

var cumulativeValues = [min];
for (var i = 1; i < count; i++) {
cumulativeValues.push(values[i] + cumulativeValues[i-1]);
}

var sum = min;
var mean = min;
var maxAtThreshold = max;

Expand All @@ -84,27 +90,27 @@ var flush_stats = function graphite_flush(ts, metrics) {
if (count > 1) {
var thresholdIndex = Math.round(((100 - pct) / 100) * count);
var numInThreshold = count - thresholdIndex;
var pctValues = values.slice(0, numInThreshold);
maxAtThreshold = pctValues[numInThreshold - 1];

// average the remaining timings
var sum = 0;
for (var i = 0; i < numInThreshold; i++) {
sum += pctValues[i];
}

maxAtThreshold = values[numInThreshold - 1];
sum = cumulativeValues[numInThreshold - 1];
mean = sum / numInThreshold;
}

var clean_pct = '' + pct;
clean_pct.replace('.', '_');
message += 'stats.timers.' + key + '.mean_' + clean_pct + ' ' + mean + ' ' + ts + "\n";
message += 'stats.timers.' + key + '.upper_' + clean_pct + ' ' + maxAtThreshold + ' ' + ts + "\n";
message += 'stats.timers.' + key + '.sum_' + clean_pct + ' ' + sum + ' ' + ts + "\n";
}

sum = cumulativeValues[count-1];
mean = sum / count;

message += 'stats.timers.' + key + '.upper ' + max + ' ' + ts + "\n";
message += 'stats.timers.' + key + '.lower ' + min + ' ' + ts + "\n";
message += 'stats.timers.' + key + '.count ' + count + ' ' + ts + "\n";
message += 'stats.timers.' + key + '.sum ' + sum + ' ' + ts + "\n";
message += 'stats.timers.' + key + '.mean ' + mean + ' ' + ts + "\n";
statString += message;

numStats += 1;
Expand Down

0 comments on commit ffacf28

Please sign in to comment.