forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update readme and changelog for template processor
- Loading branch information
1 parent
15d0166
commit 5f2f2ff
Showing
5 changed files
with
81 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,59 @@ | ||
# Template Processor | ||
|
||
The `template` processor applies a go template to tag, field, measurement and time values to create a new tag. | ||
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. | ||
|
||
Golang [Template Documentation] | ||
The template has access to each metric's measurement name, tags, fields, and | ||
timestamp using the [interface in `/template_metric.go`](template_metric.go). | ||
|
||
Read the full [Go Template Documentation][]. | ||
|
||
### Configuration | ||
|
||
```toml | ||
# Concatenate two tags to create a new tag | ||
[[processors.template]] | ||
## Tag to create | ||
tag = "topic" | ||
## Template to create tag | ||
# Note: Single quotes (') are used, so the double quotes (") don't need escaping (\") | ||
template = '{{ .Tag "hostname" }}.{{ .Tag "level" }}' | ||
[[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: | ||
```toml | ||
[[processors.template]] | ||
tag = "topic" | ||
template = '{{ .Tag "hostname" }}.{{ .Tag "level" }}' | ||
``` | ||
|
||
```diff | ||
- 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: | ||
```toml | ||
[[processors.template]] | ||
tag = "measurement" | ||
template = '{{ .Name }}' | ||
``` | ||
|
||
```diff | ||
- cpu,level=debug,hostname=localhost value=42i | ||
+ cpu,level=debug,hostname=localhost,topic=localhost.debug value=42i | ||
- cpu,hostname=localhost time_idle=42 | ||
+ cpu,hostname=localhost,meaurement=cpu time_idle=42 | ||
``` | ||
|
||
Add the year as a tag, similar to the date processor: | ||
```toml | ||
[[processors.template]] | ||
tag = "year" | ||
template = '{{.Time.UTC.Year}}' | ||
``` | ||
|
||
[Template Documentation]:https://golang.org/pkg/text/template/ | ||
[Go Template Documentation]: https://golang.org/pkg/text/template/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters