telegraf/plugins/processors/template
Paweł Żak 2b1a79f327
fix: Linter fixes for plugins/processors/[a-z]* (#10161)
Co-authored-by: Pawel Zak <Pawel Zak>
2021-11-24 12:38:08 -07:00
..
README.md chore: clean up all markdown lint errors in processor plugins (#10157) 2021-11-24 11:47:11 -07:00
template.go Update readme and changelog for template processor 2020-02-06 13:34:36 -08:00
template_metric.go Fix Name field in template processor (#7258) 2020-04-13 10:57:48 -07:00
template_test.go fix: Linter fixes for plugins/processors/[a-z]* (#10161) 2021-11-24 12:38:08 -07:00

README.md

Template Processor

The template processor applies a Go template to metrics to generate a new tag. The primary use case of this plugin is to create a tag that can be used for dynamic routing to multiple output plugins or using an output specific routing option.

The template has access to each metric's measurement name, tags, fields, and timestamp using the interface in /template_metric.go.

Read the full Go Template Documentation.

Configuration

[[processors.template]]
  ## Tag to set with the output of the template.
  tag = "topic"

  ## Go template used to create the tag value.  In order to ease TOML
  ## escaping requirements, you may wish to use single quotes around the
  ## template string.
  template = '{{ .Tag "hostname" }}.{{ .Tag "level" }}'

Example

Combine multiple tags to create a single tag:

[[processors.template]]
  tag = "topic"
  template = '{{ .Tag "hostname" }}.{{ .Tag "level" }}'
- cpu,level=debug,hostname=localhost time_idle=42
+ cpu,level=debug,hostname=localhost,topic=localhost.debug time_idle=42

Add measurement name as a tag:

[[processors.template]]
  tag = "measurement"
  template = '{{ .Name }}'
- cpu,hostname=localhost time_idle=42
+ cpu,hostname=localhost,measurement=cpu time_idle=42

Add the year as a tag, similar to the date processor:

[[processors.template]]
  tag = "year"
  template = '{{.Time.UTC.Year}}'