Add configurable separator graphite serializer and output (#7545)

This commit is contained in:
ihard
2020-05-21 03:15:18 +03:00
committed by GitHub
parent 10560e5a10
commit 94c75b51a8
10 changed files with 327 additions and 8 deletions

View File

@@ -39,6 +39,7 @@ type GraphiteSerializer struct {
Prefix string
Template string
TagSupport bool
Separator string
Templates []*GraphiteTemplate
}
@@ -55,7 +56,7 @@ func (s *GraphiteSerializer) Serialize(metric telegraf.Metric) ([]byte, error) {
if fieldValue == "" {
continue
}
bucket := SerializeBucketNameWithTags(metric.Name(), metric.Tags(), s.Prefix, fieldName)
bucket := SerializeBucketNameWithTags(metric.Name(), metric.Tags(), s.Prefix, s.Separator, fieldName)
metricString := fmt.Sprintf("%s %s %d\n",
// insert "field" section of template
bucket,
@@ -246,6 +247,7 @@ func SerializeBucketNameWithTags(
measurement string,
tags map[string]string,
prefix string,
separator string,
field string,
) string {
var out string
@@ -259,13 +261,13 @@ func SerializeBucketNameWithTags(
sort.Strings(tagsCopy)
if prefix != "" {
out = prefix + "."
out = prefix + separator
}
out += measurement
if field != "value" {
out += "." + field
out += separator + field
}
out = sanitize(out)