Skip to content

Commit

Permalink
sanitize known issue characters from graphite tag name
Browse files Browse the repository at this point in the history
  • Loading branch information
jipperinbham committed Mar 21, 2016
1 parent 2207304 commit e940f99
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
9 changes: 1 addition & 8 deletions plugins/outputs/librato/librato.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"log"
"net/http"
"strings"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion plugins/serializers/graphite/graphite.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type GraphiteSerializer struct {
Prefix string
}

var sanitizedChars = strings.NewReplacer("/", "-", "@", "-", " ", "_")

func (s *GraphiteSerializer) Serialize(metric telegraf.Metric) ([]string, error) {
out := []string{}

Expand Down Expand Up @@ -85,5 +87,5 @@ func buildTags(metric telegraf.Metric) string {
tag_str += "." + tag_value
}
}
return tag_str
return sanitizedChars.Replace(tag_str)
}

0 comments on commit e940f99

Please sign in to comment.