From e9992980780ac57f64fe720438bafd1d62b5f63b Mon Sep 17 00:00:00 2001 From: David Norton Date: Wed, 14 Sep 2016 13:32:43 -0400 Subject: [PATCH] speed up statsd parser --- CHANGELOG.md | 1 + plugins/inputs/statsd/statsd.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 369b93361..c5045196c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - [#1716](https://github.com/influxdata/telegraf/issues/1716): Sensors plugin strconv.ParseFloat: parsing "": invalid syntax - [#1530](https://github.com/influxdata/telegraf/issues/1530): Fix prometheus_client reload panic - [#1764](https://github.com/influxdata/telegraf/issues/1764): Fix kafka consumer panic when nil error is returned down errs channel. +- [#1768](https://github.com/influxdata/telegraf/pull/1768): Speed up statsd parsing. ## v1.0 [2016-09-08] diff --git a/plugins/inputs/statsd/statsd.go b/plugins/inputs/statsd/statsd.go index 3f646d254..6e72e632f 100644 --- a/plugins/inputs/statsd/statsd.go +++ b/plugins/inputs/statsd/statsd.go @@ -85,6 +85,8 @@ type Statsd struct { Templates []string listener *net.UDPConn + + graphiteParser *graphite.GraphiteParser } // One statsd metric, form is :||@ @@ -505,7 +507,15 @@ func (s *Statsd) parseName(bucket string) (string, string, map[string]string) { var field string name := bucketparts[0] - p, err := graphite.NewGraphiteParser(s.MetricSeparator, s.Templates, nil) + + p := s.graphiteParser + var err error + + if p == nil || s.graphiteParser.Separator != s.MetricSeparator { + p, err = graphite.NewGraphiteParser(s.MetricSeparator, s.Templates, nil) + s.graphiteParser = p + } + if err == nil { p.DefaultTags = tags name, tags, field, _ = p.ApplyTemplate(name)