Support multiple templates for graphite serializers (#7136)

This commit is contained in:
Ilya Antipov
2020-03-31 21:30:21 +03:00
committed by GitHub
parent 218fbc41b9
commit 0cad343de7
9 changed files with 308 additions and 10 deletions

View File

@@ -18,11 +18,12 @@ import (
type Graphite struct {
GraphiteTagSupport bool
// URL is only for backwards compatibility
Servers []string
Prefix string
Template string
Timeout int
conns []net.Conn
Servers []string
Prefix string
Template string
Templates []string
Timeout int
conns []net.Conn
tlsint.ClientConfig
}
@@ -40,6 +41,16 @@ var sampleConfig = `
## Enable Graphite tags support
# graphite_tag_support = false
## Graphite templates patterns
## 1. Template for cpu
## 2. Template for disk*
## 3. Default template
# templates = [
# "cpu tags.measurement.host.field",
# "disk* measurement.field",
# "host.measurement.tags.field"
#]
## timeout in seconds for the write connection to graphite
timeout = 2
@@ -134,7 +145,7 @@ func checkEOF(conn net.Conn) {
func (g *Graphite) Write(metrics []telegraf.Metric) error {
// Prepare data
var batch []byte
s, err := serializers.NewGraphiteSerializer(g.Prefix, g.Template, g.GraphiteTagSupport)
s, err := serializers.NewGraphiteSerializer(g.Prefix, g.Template, g.GraphiteTagSupport, g.Templates)
if err != nil {
return err
}