Exec 输入插件
此插件在每个间隔执行给定的 commands,并以支持的 数据格式之一解析其输出中的指标。此插件可用于轮询任何来源的自定义指标。
引入版本: Telegraf v0.1.5 标签: system 操作系统支持: all
全局配置选项
插件支持其他全局和插件配置设置,用于修改指标、标签和字段,创建别名以及配置插件顺序等任务。更多详情请参阅 CONFIGURATION.md。
配置
# Read metrics from one or more commands that can output to stdout
[[inputs.exec]]
## Commands array
commands = []
## 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 = []
## Timeout for each command to complete.
# timeout = "5s"
## Measurement name suffix
## Used for separating different commands
# name_suffix = ""
## Ignore Error Code
## If set to true, a non-zero error code in not considered an error and the
## plugin will continue to parse the output.
# ignore_error = false
## Data format
## By default, exec expects JSON. This was done for historical reasons and is
## different than other inputs that use the influx line protocol. Each data
## format has its own unique set of configuration options, read more about
## them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
# data_format = "json"command 选项中的全局模式会在每次运行时进行匹配,因此添加匹配该模式的新脚本将立即生效。
示例
此脚本生成静态值,由于未指定时间戳,因此值对应于当前时间。请确保整数值后跟 i 以便正确解析。
#!/bin/sh
echo 'example,tag1=a,tag2=b i=42i,j=43i,k=44i'它可以与以下配置配对,并将在代理的 interval 间隔内运行。
[[inputs.exec]]
commands = ["sh /tmp/test.sh"]
timeout = "5s"
data_format = "influx"常见问题
我的脚本手动运行时有效,但在 Telegraf 作为服务运行时无效
这可能与 Telegraf 服务以不同的用户身份运行有关。在 Linux 系统上,官方软件包以 telegraf 用户和组运行 Telegraf。
在 Windows PowerShell 上,脚本的输出似乎被截断了
您可能需要在脚本中设置一个变量来增加输出列的可用数量
$host.UI.RawUI.BufferSize = new-object System.Management.Automation.Host.Size(1024,50)Metrics
示例输出
此页面是否有帮助?
感谢您的反馈!
支持和反馈
感谢您成为我们社区的一员!我们欢迎并鼓励您对 Telegraf 和本文档提出反馈和 bug 报告。要获取支持,请使用以下资源
具有年度合同或支持合同的客户可以 联系 InfluxData 支持。