sanitize known issue characters from graphite tag name

This commit is contained in:
JP 2016-03-21 09:50:21 -05:00 committed by Michele Fadda
parent 7698e77eb5
commit cc10985cac
2 changed files with 4 additions and 9 deletions

View File

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

View File

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