Skip to content

Commit

Permalink
Add support for timing sums in statsd input (#3234)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpounds authored and danielnelson committed Sep 14, 2017
1 parent 875ab3c commit 171332c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions plugins/inputs/statsd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ metric type:
for that stat during that interval.
- `statsd_<name>_stddev`: The stddev is the sample standard deviation
of all values statsd saw for that stat during that interval.
- `statsd_<name>_sum`: The sum is the sample sum of all values statsd saw
for that stat during that interval.
- `statsd_<name>_count`: The count is the number of timings statsd saw
for that stat during that interval. It is not averaged.
- `statsd_<name>_percentile_<P>` The `Pth` percentile is a value x such
Expand Down
11 changes: 10 additions & 1 deletion plugins/inputs/statsd/running_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ type RunningStats struct {
perc []float64
PercLimit int

upper float64
sum float64

lower float64
upper float64

// cache if we have sorted the list so that we never re-sort a sorted list,
// which can have very bad performance.
Expand All @@ -51,6 +53,9 @@ func (rs *RunningStats) AddValue(v float64) {
rs.ex += v - rs.k
rs.ex2 += (v - rs.k) * (v - rs.k)

// add to running sum
rs.sum += v

// track upper and lower bounds
if v > rs.upper {
rs.upper = v
Expand Down Expand Up @@ -78,6 +83,10 @@ func (rs *RunningStats) Stddev() float64 {
return math.Sqrt(rs.Variance())
}

func (rs *RunningStats) Sum() float64 {
return rs.sum
}

func (rs *RunningStats) Upper() float64 {
return rs.upper
}
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func (s *Statsd) Gather(acc telegraf.Accumulator) error {
}
fields[prefix+"mean"] = stats.Mean()
fields[prefix+"stddev"] = stats.Stddev()
fields[prefix+"sum"] = stats.Sum()
fields[prefix+"upper"] = stats.Upper()
fields[prefix+"lower"] = stats.Lower()
fields[prefix+"count"] = stats.Count()
Expand Down
5 changes: 5 additions & 0 deletions plugins/inputs/statsd/statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ func TestParse_Timings(t *testing.T) {
"lower": float64(1),
"mean": float64(3),
"stddev": float64(4),
"sum": float64(15),
"upper": float64(11),
}

Expand Down Expand Up @@ -1154,13 +1155,15 @@ func TestParse_Timings_MultipleFieldsWithTemplate(t *testing.T) {
"success_lower": float64(1),
"success_mean": float64(3),
"success_stddev": float64(4),
"success_sum": float64(15),
"success_upper": float64(11),

"error_90_percentile": float64(22),
"error_count": int64(5),
"error_lower": float64(2),
"error_mean": float64(6),
"error_stddev": float64(8),
"error_sum": float64(30),
"error_upper": float64(22),
}

Expand Down Expand Up @@ -1203,6 +1206,7 @@ func TestParse_Timings_MultipleFieldsWithoutTemplate(t *testing.T) {
"lower": float64(1),
"mean": float64(3),
"stddev": float64(4),
"sum": float64(15),
"upper": float64(11),
}
expectedError := map[string]interface{}{
Expand All @@ -1211,6 +1215,7 @@ func TestParse_Timings_MultipleFieldsWithoutTemplate(t *testing.T) {
"lower": float64(2),
"mean": float64(6),
"stddev": float64(8),
"sum": float64(30),
"upper": float64(22),
}

Expand Down

0 comments on commit 171332c

Please sign in to comment.