Support negative statsd counters

closes #1898
This commit is contained in:
Cameron Sparr 2016-12-20 13:21:51 +00:00
parent a2feba21de
commit cf9fd9bb5f
3 changed files with 10 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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",