Skip to content

Commit

Permalink
added simple rollup type too
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcal committed Aug 31, 2010
1 parent 2105303 commit f100f90
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
40 changes: 36 additions & 4 deletions lib/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ function Collector(config){

for (var j in self.buckets[bucket]){

var data = self.rollupData(self.buckets[bucket][j], bucket, j);
var data = self.rollupData(j, self.buckets[bucket][j]);
data.stat = j;
data.ts = self.bucketToTime(bucket);
self.emit('data', data);
}

Expand All @@ -47,7 +49,38 @@ function Collector(config){
}
};

this.rollupData = function(vals, bucket, stat){
this.rollupData = function(stat, vals){

if (stat.match(/_ok$/)){

return self.rollupDataSimple(vals);
}else{
return self.rollupDataAvgPer(vals);
}
};

this.rollupDataSimple = function(vals){

var ok = 0;
var fail = 0;

for (var i=0; i<vals.length; i++){
if (vals[i]){
ok++;
}else{
fail++;
}
}

return {
mode: 'simple',
pass: ok,
fail: fail,
total: ok + fail,
};
};

this.rollupDataAvgPer = function(vals){

var all = vals.sort();
var num = all.length;
Expand All @@ -70,8 +103,7 @@ function Collector(config){
}

return {
stat: stat,
ts: self.bucketToTime(bucket),
mode: 'avg_per',
num: num,
lo: lo,
avg: avg,
Expand Down
1 change: 1 addition & 0 deletions rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ collector.on('data', function(data){

setInterval(function(){ collector.addData('d1', Math.random() * 10); }, 200);
setInterval(function(){ collector.addData('d2', 3); }, 300);
setInterval(function(){ collector.addData('d3_ok', (Math.random() * 10) > 6 ? 1 : 0); }, 100);

0 comments on commit f100f90

Please sign in to comment.