From cf9fd9bb5f2f97f01880d6208ff6a0bee4e9648c Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Tue, 20 Dec 2016 13:21:51 +0000 Subject: [PATCH] Support negative statsd counters closes #1898 --- CHANGELOG.md | 3 ++- plugins/inputs/statsd/statsd.go | 4 ++-- plugins/inputs/statsd/statsd_test.go | 8 ++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 751ee1eaa..b228a891d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,8 @@ in their config file. - [#2078](https://github.com/influxdata/telegraf/pull/2078): Ping input: add standard deviation field. - [#2121](https://github.com/influxdata/telegraf/pull/2121): Add GC pause metric to InfluxDB input plugin. - [#2006](https://github.com/influxdata/telegraf/pull/2006): Added response_timeout property to prometheus input plugin. -- [#1763](https://github.com/influxdata/telegraf/issues/1763): Pulling github.com/lxn/win's pdh wrapper into telegraf +- [#1763](https://github.com/influxdata/telegraf/issues/1763): Pulling github.com/lxn/win's pdh wrapper into telegraf. +- [#1898](https://github.com/influxdata/telegraf/issues/1898): Support negative statsd counters. ### Bugfixes diff --git a/plugins/inputs/statsd/statsd.go b/plugins/inputs/statsd/statsd.go index 75dfc915e..1b0189a9e 100644 --- a/plugins/inputs/statsd/statsd.go +++ b/plugins/inputs/statsd/statsd.go @@ -426,8 +426,8 @@ func (s *Statsd) parseStatsdLine(line string) error { // Parse the value if strings.HasPrefix(pipesplit[0], "-") || strings.HasPrefix(pipesplit[0], "+") { - if m.mtype != "g" { - log.Printf("E! Error: +- values are only supported for gauges: %s\n", line) + if m.mtype != "g" && m.mtype != "c" { + log.Printf("E! Error: +- values are only supported for gauges & counters: %s\n", line) return errors.New("Error Parsing statsd line") } m.additive = true diff --git a/plugins/inputs/statsd/statsd_test.go b/plugins/inputs/statsd/statsd_test.go index 9fbaf5372..ff3002d2c 100644 --- a/plugins/inputs/statsd/statsd_test.go +++ b/plugins/inputs/statsd/statsd_test.go @@ -197,6 +197,8 @@ func TestParse_Counters(t *testing.T) { "sample.rate:1|c|@0.1", "sample.rate:1|c", "scientific.notation:4.696E+5|c", + "negative.test:100|c", + "negative.test:-5|c", } for _, line := range valid_lines { @@ -230,6 +232,10 @@ func TestParse_Counters(t *testing.T) { "sample_rate", 11, }, + { + "negative_test", + 95, + }, } for _, test := range validations { @@ -299,11 +305,9 @@ func TestParse_InvalidLines(t *testing.T) { "i.dont.have.a.pipe:45g", "i.dont.have.a.colon45|c", "invalid.metric.type:45|e", - "invalid.plus.minus.non.gauge:+10|c", "invalid.plus.minus.non.gauge:+10|s", "invalid.plus.minus.non.gauge:+10|ms", "invalid.plus.minus.non.gauge:+10|h", - "invalid.plus.minus.non.gauge:-10|c", "invalid.value:foobar|c", "invalid.value:d11|c", "invalid.value:1d1|c",