文档文档

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 = 56

Ping 方法

该插件主要有两种操作模式:execnative。后者是推荐的方式,因为它提供了更好的系统兼容性和性能。然而,为了向后兼容,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 telegraf

Linux 权限

在使用 native 模式时,Telegraf 将尝试使用特权的原始 ICMP 套接字。在大多数系统中,这样做需要 CAP_NET_RAW 功能或以 root 身份运行 Telegraf。

使用 systemd

systemctl edit telegraf
[Service]
CapabilityBoundingSet=CAP_NET_RAW
AmbientCapabilities=CAP_NET_RAW
systemctl 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)

reply_received 与 packets_received

在 Windows 系统中,当 method = "exec" 时,“Destination net unreachable” 回复将增加 packets_received,但不会增加 reply_received*。

ttl

目前在 Windows 上使用 "native" 模式不支持 TTL;请关注 https://github.com/golang/go/issues/7175https://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

此页面是否有帮助?

感谢您的反馈!


InfluxDB 3.8 新特性

InfluxDB 3.8 和 InfluxDB 3 Explorer 1.6 的主要增强功能。

查看博客文章

InfluxDB 3.8 现已适用于 Core 和 Enterprise 版本,同时发布了 InfluxDB 3 Explorer UI 的 1.6 版本。本次发布着重于操作成熟度,以及如何更轻松地部署、管理和可靠地运行 InfluxDB。

更多信息,请查看

InfluxDB Docker 的 latest 标签将指向 InfluxDB 3 Core

在 **2026 年 2 月 3 日**,InfluxDB Docker 镜像的 latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。

如果使用 Docker 来安装和运行 InfluxDB,latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。例如,如果使用 Docker 运行 InfluxDB v2,请将 latest 版本标签替换为 Docker pull 命令中的特定版本标签 — 例如

docker pull influxdb:2