From 7655a2021346198e7976d454f6456631fae25e8b Mon Sep 17 00:00:00 2001 From: Biplab Sarkar Date: Tue, 25 Oct 2016 16:20:50 +0530 Subject: [PATCH] Support for deletion of gauge for statsd plugin. e.g: echo "mytable,mymeas=1:+10|gd" | nc -w 1 -u localhost 8125 --- plugins/inputs/statsd/statsd.go | 15 +++++++++++---- scripts/build.py | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/inputs/statsd/statsd.go b/plugins/inputs/statsd/statsd.go index a46af0a87..b772bd5c3 100644 --- a/plugins/inputs/statsd/statsd.go +++ b/plugins/inputs/statsd/statsd.go @@ -411,7 +411,7 @@ func (s *Statsd) parseStatsdLine(line string) error { // Validate metric type switch pipesplit[1] { - case "g", "c", "s", "ms", "h": + case "g", "c", "s", "ms", "h", "gd": m.mtype = pipesplit[1] default: log.Printf("E! Error: Statsd Metric type %s unsupported", pipesplit[1]) @@ -420,7 +420,7 @@ func (s *Statsd) parseStatsdLine(line string) error { // Parse the value if strings.HasPrefix(pipesplit[0], "-") || strings.HasPrefix(pipesplit[0], "+") { - if m.mtype != "g" { + if m.mtype != "g" && m.mtype != "gd" { log.Printf("E! Error: +- values are only supported for gauges: %s\n", line) return errors.New("Error Parsing statsd line") } @@ -428,7 +428,7 @@ func (s *Statsd) parseStatsdLine(line string) error { } switch m.mtype { - case "g", "ms", "h": + case "g", "ms", "h", "gd": v, err := strconv.ParseFloat(pipesplit[0], 64) if err != nil { log.Printf("E! Error: parsing value to float64: %s\n", line) @@ -458,7 +458,7 @@ func (s *Statsd) parseStatsdLine(line string) error { switch m.mtype { case "c": m.tags["metric_type"] = "counter" - case "g": + case "g", "gd": m.tags["metric_type"] = "gauge" case "s": m.tags["metric_type"] = "set" @@ -598,6 +598,13 @@ func (s *Statsd) aggregate(m metric) { } s.counters[m.hash].fields[m.field] = s.counters[m.hash].fields[m.field].(int64) + m.intvalue + + case "gd": + // delete a gauge if it exists + _, ok := s.gauges[m.hash] + if ok { + delete (s.gauges,m.hash) + } case "g": // check if the measurement exists _, ok := s.gauges[m.hash] diff --git a/scripts/build.py b/scripts/build.py index 77befd599..3bee22865 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -84,7 +84,7 @@ targets = { supported_builds = { "windows": [ "amd64" ], - "linux": [ "amd64", "i386", "armhf", "armel", "arm64", "static_amd64" ], + "linux": [ "static_amd64", "amd64", "i386", "armhf", "armel", "arm64" ], "freebsd": [ "amd64" ] }