模板处理器插件
此插件将模板应用于指标以生成新标签。此插件的主要用例是创建一个可用于动态路由到多个输出插件或使用特定于输出的路由选项的标签。
模板可以访问每个指标的度量名称、标签、字段和时间戳。模板遵循Go Template 语法,并且可能包含Sprig 函数。
引入于: Telegraf v1.14.0 标签: transformation 操作系统支持: all
全局配置选项
插件支持其他全局和插件配置设置,用于修改指标、标签和字段,创建别名以及配置插件顺序等任务。更多详情请参阅 CONFIGURATION.md。
配置
# Uses a Go template to create a new tag
[[processors.template]]
## Go template used to create the tag name of the output. In order to
## ease TOML escaping requirements, you should use single quotes around
## the template string.
tag = "topic"
## Go template used to create the tag value of the output. In order to
## ease TOML escaping requirements, you should use single quotes around
## the template string.
template = '{{ .Tag "hostname" }}.{{ .Tag "level" }}'示例
组合多个标签以创建单个标签
[[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
使用字段值作为标签名
[[processors.template]]
tag = '{{ .Field "type" }}'
template = '{{ .Name }}'- cpu,level=debug,hostname=localhost time_idle=42,type=sensor
+ cpu,level=debug,hostname=localhost,sensor=cpu time_idle=42,type=sensor
添加测量名称作为标签
[[processors.template]]
tag = "measurement"
template = '{{ .Name }}'- cpu,hostname=localhost time_idle=42
+ cpu,hostname=localhost,measurement=cpu time_idle=42
添加年份作为标签,类似于日期处理器
[[processors.template]]
tag = "year"
template = '{{.Time.UTC.Year}}'将所有字段添加为标签
有时将所有字段及其值传递到单个消息中以发送到监控系统(例如 Syslog、GroundWork)非常有用,然后您可以使用 .Fields 或 .Tags
[[processors.template]]
tag = "message"
template = 'Message about {{.Name}} fields: {{.Fields}}'- cpu,hostname=localhost time_idle=42
+ cpu,hostname=localhost,message=Message\ about\ cpu\ fields:\ map[time_idle:42] time_idle=42
更高级的示例,可能更有意义
[[processors.template]]
tag = "message"
template = '''Message about {{.Name}} fields:
{{ range $field, $value := .Fields -}}
{{$field}}:{{$value}}
{{ end }}'''- cpu,hostname=localhost time_idle=42
+ cpu,hostname=localhost,message=Message\ about\ cpu\ fields:\ntime_idle:42\n time_idle=42
只需将当前指标添加为标签
[[processors.template]]
tag = "metric"
template = '{{.}}'- cpu,hostname=localhost time_idle=42
+ cpu,hostname=localhost,metric=cpu\ map[hostname:localhost]\ map[time_idle:42]\ 1257894000000000000 time_idle=42
此页面是否有帮助?
感谢您的反馈!
支持和反馈
感谢您成为我们社区的一员!我们欢迎并鼓励您对 Telegraf 和本文档提出反馈和 bug 报告。要获取支持,请使用以下资源
具有年度合同或支持合同的客户可以 联系 InfluxData 支持。