From e940f99646d46a3e22d206a1067ea3ea4ab4426e Mon Sep 17 00:00:00 2001 From: JP Date: Mon, 21 Mar 2016 09:50:21 -0500 Subject: [PATCH] sanitize known issue characters from graphite tag name --- plugins/outputs/librato/librato.go | 9 +-------- plugins/serializers/graphite/graphite.go | 4 +++- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/plugins/outputs/librato/librato.go b/plugins/outputs/librato/librato.go index 406f45361..910ac8b4e 100644 --- a/plugins/outputs/librato/librato.go +++ b/plugins/outputs/librato/librato.go @@ -7,7 +7,6 @@ import ( "io/ioutil" "log" "net/http" - "strings" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/internal" @@ -156,13 +155,7 @@ func (l *Librato) Description() string { func (l *Librato) buildGaugeName(m telegraf.Metric, fieldName string) string { // Use the GraphiteSerializer graphiteSerializer := graphite.GraphiteSerializer{} - serializedMetric := graphiteSerializer.SerializeBucketName(m, fieldName) - - // Deal with slash characters: - replacedString := strings.Replace(serializedMetric, "/", "-", -1) - // Deal with @ characters: - replacedString = strings.Replace(replacedString, "@", "-", -1) - return replacedString + return graphiteSerializer.SerializeBucketName(m, fieldName) } func (l *Librato) buildGauges(m telegraf.Metric) ([]*Gauge, error) { diff --git a/plugins/serializers/graphite/graphite.go b/plugins/serializers/graphite/graphite.go index 908dce8fa..7a7fec2f1 100644 --- a/plugins/serializers/graphite/graphite.go +++ b/plugins/serializers/graphite/graphite.go @@ -12,6 +12,8 @@ type GraphiteSerializer struct { Prefix string } +var sanitizedChars = strings.NewReplacer("/", "-", "@", "-", " ", "_") + func (s *GraphiteSerializer) Serialize(metric telegraf.Metric) ([]string, error) { out := []string{} @@ -85,5 +87,5 @@ func buildTags(metric telegraf.Metric) string { tag_str += "." + tag_value } } - return tag_str + return sanitizedChars.Replace(tag_str) }