Merge pull request #277 from dynmeth/master

Added median calculation to timer_data
This commit is contained in:
Daniel Schauenberg 2013-03-23 14:49:26 -07:00
Родитель a11359d3a9 76c13f03fa
Коммит 8bc1bb3f5d
2 изменённых файлов: 16 добавлений и 2 удалений

Просмотреть файл

@ -64,6 +64,9 @@ var process_metrics = function (metrics, flushInterval, ts, flushCallback) {
sumOfDiffs += (values[i] - mean) * (values[i] - mean);
}
var mid = Math.floor(count/2);
var median = (count % 2) ? values[mid] : (values[mid-1] + values[mid])/2;
var stddev = Math.sqrt(sumOfDiffs / count);
current_timer_data["std"] = stddev;
current_timer_data["upper"] = max;
@ -72,6 +75,7 @@ var process_metrics = function (metrics, flushInterval, ts, flushCallback) {
current_timer_data["count_ps"] = timer_counters[key] / (flushInterval / 1000);
current_timer_data["sum"] = sum;
current_timer_data["mean"] = mean;
current_timer_data["median"] = median;
// note: values bigger than the upper limit of the last bin are ignored, by design
conf = histogram || [];

Просмотреть файл

@ -46,7 +46,7 @@ module.exports = {
test.done();
},
timers_single_time: function(test) {
test.expect(7);
test.expect(8);
this.metrics.timers['a'] = [100];
this.metrics.timer_counters['a'] = 1;
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
@ -58,10 +58,11 @@ module.exports = {
test.equal(10, timer_data.count_ps);
test.equal(100, timer_data.sum);
test.equal(100, timer_data.mean);
test.equal(100, timer_data.median);
test.done();
},
timers_multiple_times: function(test) {
test.expect(7);
test.expect(8);
this.metrics.timers['a'] = [100, 200, 300];
this.metrics.timer_counters['a'] = 3;
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
@ -73,6 +74,7 @@ module.exports = {
test.equal(30, timer_data.count_ps);
test.equal(600, timer_data.sum);
test.equal(200, timer_data.mean);
test.equal(200, timer_data.median);
test.done();
},
timers_single_time_single_percentile: function(test) {
@ -190,5 +192,13 @@ module.exports = {
statsd_metrics = this.metrics.statsd_metrics;
test.notEqual(undefined, statsd_metrics["processing_time"]);
test.done();
},
timers_multiple_times_even: function(test) {
test.expect(1);
this.metrics.timers['a'] = [300, 200, 400, 100];
pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
timer_data = this.metrics.timer_data['a'];
test.equal(250, timer_data.median);
test.done();
}
}