Ping 输入插件
此插件收集有关 ICMP ping 数据包的指标,包括往返时间、响应时间和数据包统计信息。
在使用 exec 方法时,ping 命令必须在系统上可用,并且 Telegraf 可以执行它。
引入于: Telegraf v0.1.8 标签: network 操作系统支持: all
全局配置选项
插件支持其他全局和插件配置设置,用于修改指标、标签和字段,创建别名以及配置插件顺序等任务。更多详情请参阅 CONFIGURATION.md。
配置
# Ping given url(s) and return statistics
[[inputs.ping]]
## Hosts to send ping packets to.
urls = ["example.org"]
## Method used for sending pings, can be either "exec" or "native". When set
## to "exec" the systems ping command will be executed. When set to "native"
## the plugin will send pings directly.
##
## While the default is "exec" for backwards compatibility, new deployments
## are encouraged to use the "native" method for improved compatibility and
## performance.
# method = "exec"
## Number of ping packets to send per interval. Corresponds to the "-c"
## option of the ping command.
# count = 1
## Time to wait between sending ping packets in seconds. Operates like the
## "-i" option of the ping command.
# ping_interval = 1.0
## If set, the time to wait for a ping response in seconds. Operates like
## the "-W" option of the ping command.
# timeout = 1.0
## If set, the total ping deadline, in seconds. Operates like the -w option
## of the ping command.
# deadline = 10
## Interface or source address to send ping from. Operates like the -I or -S
## option of the ping command.
# interface = ""
## Percentiles to calculate. This only works with the native method.
# percentiles = [50, 95, 99]
## Specify the ping executable binary.
# binary = "ping"
## Arguments for ping command. When arguments is not empty, the command from
## the binary option will be used and other options (ping_interval, timeout,
## etc) will be ignored.
# arguments = ["-c", "3"]
## Use only IPv4 addresses when resolving a hostname. By default, both IPv4
## and IPv6 can be used.
# ipv4 = false
## Use only IPv6 addresses when resolving a hostname. By default, both IPv4
## and IPv6 can be used.
# ipv6 = false
## Number of data bytes to be sent. Corresponds to the "-s"
## option of the ping command. This only works with the native method.
# size = 56Ping 方法
该插件主要有两种操作模式:exec 和 native。后者是推荐的方式,因为它提供了更好的系统兼容性和性能。然而,为了向后兼容,exec 模式是默认模式。
在使用 exec 模式时,大多数 ping 命令实现都得到支持,一个显著的例外是 GNU inetutils ping。您可以改用 iputils-ping 实现。
apt-get install iputils-ping对于 native 模式,会发送一个相应的 ICMP 数据包,并由 Telegraf 进程在原生 Go 中报告结果,从而无需执行系统 ping 命令。因此,此模式没有外部依赖项。
文件限制
由于此插件运行 ping 命令,它可能需要为每个主机打开多个文件。使用 native 选项可以减少使用的文件数,但仍然会使用很多文件。对于大型主机列表,您可能会收到 too many open files 错误。
要在使用 systemd 的平台上增加此限制,推荐的方法是使用“drop-in 目录”,通常位于 /etc/systemd/system/telegraf.service.d。
您可以使用以下方法在正确的位置创建或编辑 drop-in 文件:
systemctl edit telegraf增加打开文件数
[Service]
LimitNOFILE=8192重启 Telegraf
systemctl restart telegrafLinux 权限
在使用 native 模式时,Telegraf 将尝试使用特权的原始 ICMP 套接字。在大多数系统中,这样做需要 CAP_NET_RAW 功能或以 root 身份运行 Telegraf。
使用 systemd
systemctl edit telegraf[Service]
CapabilityBoundingSet=CAP_NET_RAW
AmbientCapabilities=CAP_NET_RAWsystemctl restart telegraf未使用 systemd
setcap cap_net_raw=eip /usr/bin/telegraf有关设置功能的更多信息,请参考 man 7 capabilities。
其他操作系统权限
在使用 method = "native" 时,您将需要与您的操作系统上可执行的 ping 程序类似的权限。
Metrics
- ping
- 标签 (tags)
- url
- 字段 (fields)
- packets_transmitted (integer)
- packets_received (integer)
- percent_packet_loss (float)
- ttl (integer, Windows 不可用)
- average_response_ms (float)
- minimum_response_ms (float)
- maximum_response_ms (float)
- standard_deviation_ms (float, 仅在 Windows 且 method = “native” 时可用)
- percentile<N>_ms (float, 其中
<N>是percentiles中指定的百分位数。仅在 method = “native” 时可用) - errors (float, 仅限 Windows)
- reply_received (integer, 仅限 Windows 且 method = “exec”)
- percent_reply_loss (float, 仅限 Windows 且 method = “exec”)
- result_code (int, success = 0, no such host = 1, ping error = 2)
- 标签 (tags)
reply_received 与 packets_received
在 Windows 系统中,当 method = "exec" 时,“Destination net unreachable” 回复将增加 packets_received,但不会增加 reply_received*。
ttl
目前在 Windows 上使用 "native" 模式不支持 TTL;请关注 https://github.com/golang/go/issues/7175 和 https://github.com/golang/go/issues/7174 的进展。
示例输出
ping,url=example.org average_response_ms=23.066,ttl=63,maximum_response_ms=24.64,minimum_response_ms=22.451,packets_received=5i,packets_transmitted=5i,percent_packet_loss=0,result_code=0i,standard_deviation_ms=0.809 1535747258000000000此页面是否有帮助?
感谢您的反馈!
支持和反馈
感谢您成为我们社区的一员!我们欢迎并鼓励您对 Telegraf 和本文档提出反馈和 bug 报告。要获取支持,请使用以下资源
具有年度合同或支持合同的客户可以 联系 InfluxData 支持。