Execd 处理器插件
此插件作为一个单独的进程运行外部程序,并将指标通过 stdin 管道传输到进程,并从其 stdout 读取已处理的指标。stderr 上的程序输出将被记录。
引入版本: Telegraf v1.15.0 标签: 通用 操作系统支持: 全部
注意事项
- 带有跟踪的指标将在传递给外部进程后立即被视为“已发送”。目前无法将 execd 进程输出的哪个指标与输入的哪个指标匹配(请记住,处理器可以添加和删除指标,并且所有这些都是异步完成的)。
- 由于需要序列化-解析对称且不丢失任何关键类型数据,因此目前无法使用除“influx”以外的任何 data_format。
全局配置选项
插件支持其他全局和插件配置设置,用于修改指标、标签和字段,创建别名以及配置插件顺序等任务。更多详情请参阅 CONFIGURATION.md。
配置
# Run executable as long-running processor plugin
[[processors.execd]]
## One program to run as daemon.
## NOTE: process and each argument should each be their own string
## eg: command = ["/path/to/your_program", "arg1", "arg2"]
command = ["cat"]
## Environment variables
## Array of "key=value" pairs to pass as environment variables
## e.g. "KEY=value", "USERNAME=John Doe",
## "LD_LIBRARY_PATH=/opt/custom/lib64:/usr/local/libs"
# environment = []
## Delay before the process is restarted after an unexpected termination
# restart_delay = "10s"
## Serialization format for communicating with the executed program
## Please note that the corresponding data-format must exist both in
## parsers and serializers
# data_format = "influx"示例
Go 守护进程示例
这个 Go 守护进程从标准输入读取指标,将“count”字段乘以 2,然后将指标写回。
package main
import (
"fmt"
"os"
"github.com/influxdata/telegraf/metric"
"github.com/influxdata/telegraf/plugins/parsers/influx"
serializers_influx "github.com/influxdata/telegraf/plugins/serializers/influx"
)
func main() {
parser := influx.NewStreamParser(os.Stdin)
serializer := serializers_influx.Serializer{}
if err := serializer.Init(); err != nil {
fmt.Fprintf(os.Stderr, "serializer init failed: %v\n", err)
os.Exit(1)
}
for {
metric, err := parser.Next()
if err != nil {
if err == influx.EOF {
return // stream ended
}
if parseErr, isParseError := err.(*influx.ParseError); isParseError {
fmt.Fprintf(os.Stderr, "parse ERR %v\n", parseErr)
os.Exit(1)
}
fmt.Fprintf(os.Stderr, "ERR %v\n", err)
os.Exit(1)
}
c, found := metric.GetField("count")
if !found {
fmt.Fprintf(os.Stderr, "metric has no count field\n")
os.Exit(1)
}
switch t := c.(type) {
case float64:
t *= 2
metric.AddField("count", t)
case int64:
t *= 2
metric.AddField("count", t)
default:
fmt.Fprintf(os.Stderr, "count is not an unknown type, it's a %T\n", c)
os.Exit(1)
}
b, err := serializer.Serialize(metric)
if err != nil {
fmt.Fprintf(os.Stderr, "ERR %v\n", err)
os.Exit(1)
}
fmt.Fprint(os.Stdout, string(b))
}
}要运行它,您可以使用 go 构建二进制文件,例如 go build -o multiplier.exe main.go
[[processors.execd]]
command = ["multiplier.exe"]Ruby 守护进程
- 请参阅 Ruby 守护进程
[[processors.execd]]
command = ["ruby", "plugins/processors/execd/examples/multiplier_line_protocol/multiplier_line_protocol.rb"]此页面是否有帮助?
感谢您的反馈!
支持和反馈
感谢您成为我们社区的一员!我们欢迎并鼓励您对 Telegraf 和本文档提出反馈和 bug 报告。要获取支持,请使用以下资源
具有年度合同或支持合同的客户可以 联系 InfluxData 支持。