Add configurable separator for metrics and fields in opentsdb output (#3106)

This commit is contained in:
owlet123 2017-09-27 20:29:40 +02:00 committed by Daniel Nelson
parent 084f73c0ea
commit f634414935
1 changed files with 8 additions and 2 deletions

View File

@ -33,6 +33,8 @@ type OpenTSDB struct {
HttpBatchSize int HttpBatchSize int
Debug bool Debug bool
Separator string
} }
var sampleConfig = ` var sampleConfig = `
@ -53,6 +55,9 @@ var sampleConfig = `
## Debug true - Prints OpenTSDB communication ## Debug true - Prints OpenTSDB communication
debug = false debug = false
## Separator separates measurements
separator = "."
` `
func ToLineFormat(tags map[string]string) string { func ToLineFormat(tags map[string]string) string {
@ -133,7 +138,8 @@ func (o *OpenTSDB) WriteHttp(metrics []telegraf.Metric, u *url.URL) error {
} }
metric := &HttpMetric{ metric := &HttpMetric{
Metric: sanitize(fmt.Sprintf("%s%s_%s", o.Prefix, m.Name(), fieldName)), Metric: sanitize(fmt.Sprintf("%s%s%s%s",
o.Prefix, m.Name(), o.Separator, fieldName)),
Tags: tags, Tags: tags,
Timestamp: now, Timestamp: now,
Value: value, Value: value,
@ -183,7 +189,7 @@ func (o *OpenTSDB) WriteTelnet(metrics []telegraf.Metric, u *url.URL) error {
} }
messageLine := fmt.Sprintf("put %s %v %s %s\n", messageLine := fmt.Sprintf("put %s %v %s %s\n",
sanitize(fmt.Sprintf("%s%s_%s", o.Prefix, m.Name(), fieldName)), sanitize(fmt.Sprintf("%s%s%s%s", o.Prefix, m.Name(), o.Separator, fieldName)),
now, metricValue, tags) now, metricValue, tags)
_, err := connection.Write([]byte(messageLine)) _, err := connection.Write([]byte(messageLine))