Skip to content

Commit

Permalink
Add sum aggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
rs committed Mar 9, 2018
1 parent 7d12d4c commit cb5c1d0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Available aggregators:

* `min`, `max`, `mean`: Computes the min, max, mean of the field's values during the sample interval.
* `median`, `p#`: The p1 to p99 compute the percentile of the field's values during the sample interval.
* `sum`: Sum all values for the field.
* `[bucket1,bucketN]hist`: Count number of values between bucket and bucket+1.
* `[bucket1,bucketN]cat`: Count number of values equal to the define buckets (can be non-number values). The special `*` matches values that fit in none of the defined buckets.

Expand All @@ -64,16 +65,15 @@ Jaggr can be used to integrate [vegeta](https://github.com/tsenart/vegeta) with

```
echo 'GET http://localhost:8080' | \
vegeta attack -rate 5000 -workers 100 -duration 10m | vegeta dump | \
vegeta attack -rate 5000 -duration 10m | vegeta dump | \
jaggr @count=rps \
hist[100,200,300,400,500]:code \
hist\[100,200,300,400,500\]:code \
p25,p50,p95:latency \
p25,p50,p95:bytes_in \
p25,p50,p95:bytes_out | \
sum:bytes_in \
sum:bytes_out | \
jplot rps+code.hist.100+code.hist.200+code.hist.300+code.hist.400+code.hist.500 \
latency.p95+latency.p50+latency.p25 \
bytes_in.p95+bytes_in.p50+bytes_in.p25 \
bytes_out.p95+bytes_out.p50+bytes_out.p25
bytes_in.sum+bytes_out.sum
```

![](doc/vegeta.gif)
1 change: 1 addition & 0 deletions aggr/aggr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func init() {
Register("max", newMax)
Register("mean", newMean)
Register("median", newMedian)
Register("sum", newSum)
Register("hist", newHist)
Register("cat", newCat)
for i := 1; i < 100; i++ {
Expand Down
24 changes: 24 additions & 0 deletions aggr/sum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package aggr

type sum struct {
v float64
}

func newSum(args []string) (Aggregator, error) {
return &sum{}, nil
}

func (a *sum) Push(v interface{}) error {
f, err := parseFloat(v)
if err != nil {
return err
}
a.v += f
return nil
}

func (a *sum) Aggr() interface{} {
v := a.v
a.v = 0
return v
}
Binary file modified doc/vegeta.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cb5c1d0

Please sign in to comment.