telegraf/plugins/inputs/ping/README.md

177 lines
5.6 KiB
Markdown
Raw Normal View History

2018-09-01 04:59:30 +08:00
# Ping Input Plugin
2018-09-01 04:59:30 +08:00
Sends a ping message by executing the system ping command and reports the results.
2019-09-21 07:49:14 +08:00
This plugin has two main methods of operation: `exec` and `native`. The
recommended method is `native`, which has greater system compatibility and
performance. However, for backwards compatibility the `exec` method is the
default.
When using `method = "exec"`, the systems ping utility is executed to send the
ping packets.
2019-04-09 06:42:28 +08:00
Most ping command implementations are supported, one notable exception being
2019-09-21 07:49:14 +08:00
that there is currently no support for GNU Inetutils ping. You may instead use
the iputils-ping implementation:
2018-09-01 04:59:30 +08:00
```
apt-get install iputils-ping
```
2019-09-21 07:49:14 +08:00
When using `method = "native"` a ping is sent and the results are reported in
native Go by the Telegraf process, eliminating the need to execute the system
`ping` command.
2016-12-15 03:47:48 +08:00
### Configuration:
2018-09-01 04:59:30 +08:00
```toml
[[inputs.ping]]
2019-09-21 07:49:14 +08:00
## Hosts to send ping packets to.
2018-09-01 04:59:30 +08:00
urls = ["example.org"]
2019-09-21 07:49:14 +08:00
## 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.
2018-09-01 04:59:30 +08:00
# count = 1
2019-09-21 07:49:14 +08:00
## Time to wait between sending ping packets in seconds. Operates like the
## "-i" option of the ping command.
2018-09-01 04:59:30 +08:00
# ping_interval = 1.0
2019-09-21 07:49:14 +08:00
## If set, the time to wait for a ping response in seconds. Operates like
## the "-W" option of the ping command.
2018-09-01 04:59:30 +08:00
# timeout = 1.0
2019-09-21 07:49:14 +08:00
## If set, the total ping deadline, in seconds. Operates like the -w option
## of the ping command.
2018-09-01 04:59:30 +08:00
# deadline = 10
2019-09-21 07:49:14 +08:00
## Interface or source address to send ping from. Operates like the -I or -S
## option of the ping command.
2018-09-01 04:59:30 +08:00
# interface = ""
## Percentiles to calculate. This only works with the native method.
# percentiles = [50, 95, 99]
2019-09-21 07:49:14 +08:00
## Specify the ping executable binary.
# binary = "ping"
2019-09-21 07:49:14 +08:00
## 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"]
2019-09-21 07:49:14 +08:00
## Use only IPv6 addresses when resolving a hostname.
# ipv6 = false
```
#### File Limit
2019-09-21 07:49:14 +08:00
Since this plugin runs the ping command, it may need to open multiple files per
host. The number of files used is lessened with the `native` option but still
many files are used. With a large host list you may receive a `too many open
files` error.
2019-09-21 07:49:14 +08:00
To increase this limit on platforms using systemd the recommended method is to
use the "drop-in directory", usually located at
`/etc/systemd/system/telegraf.service.d`.
2019-09-21 07:49:14 +08:00
You can create or edit a drop-in file in the correct location using:
```sh
$ systemctl edit telegraf
```
2019-09-21 07:49:14 +08:00
Increase the number of open files:
```ini
[Service]
LimitNOFILE=8192
```
2019-09-21 07:49:14 +08:00
Restart Telegraf:
```sh
$ systemctl edit telegraf
```
2019-09-21 07:49:14 +08:00
#### Linux Permissions
When using `method = "native"`, Telegraf will attempt to use privileged raw
ICMP sockets. On most systems, doing so requires `CAP_NET_RAW` capabilities.
With systemd:
```sh
$ systemctl edit telegraf
```
2019-09-21 07:49:14 +08:00
```ini
[Service]
2019-09-21 07:49:14 +08:00
CapabilityBoundingSet=CAP_NET_RAW
AmbientCapabilities=CAP_NET_RAW
```
```sh
$ systemctl restart telegraf
```
2019-09-21 07:49:14 +08:00
Without systemd:
```sh
$ setcap cap_net_raw=eip /usr/bin/telegraf
```
2019-09-21 07:49:14 +08:00
Reference [`man 7 capabilities`][man 7 capabilities] for more information about
setting capabilities.
2019-09-21 07:49:14 +08:00
[man 7 capabilities]: http://man7.org/linux/man-pages/man7/capabilities.7.html
On Linux the default behaviour is to restrict creation of ping sockets for everybody. Execute the below command to enable creation of ping sockets for all possible user groups. The integers provided to ping_group_range defines the range of user groups that are permited to create ping sockets, were 2147483647 (the max of a signed int 2^31) is the max group identifier (GID).
2019-09-21 07:49:14 +08:00
```sh
$ sudo sysctl -w net.ipv4.ping_group_range="0 2147483647"
```
2019-09-21 07:49:14 +08:00
Reference [`man 7 icmp`][man 7 icmp] for more information about ICMP echo
sockets and the `ping_group_range` setting.
[man 7 icmp]: http://man7.org/linux/man-pages/man7/icmp.7.html
2019-09-21 07:49:14 +08:00
### Metrics
2018-09-01 04:59:30 +08:00
- ping
- tags:
- url
- fields:
- packets_transmitted (integer)
- packets_received (integer)
- percent_packet_loss (float)
2019-03-09 06:30:38 +08:00
- ttl (integer, Not available on Windows)
- average_response_ms (float)
- minimum_response_ms (float)
- maximum_response_ms (float)
- standard_deviation_ms (float, Available on Windows only with method = "native")
- percentile\<N\>_ms (float, Where `<N>` is the percentile specified in `percentiles`. Available with method = "native" only)
2018-09-01 04:59:30 +08:00
- errors (float, Windows only)
2019-09-21 07:49:14 +08:00
- reply_received (integer, Windows with method = "exec" only)
- percent_reply_loss (float, Windows with method = "exec" only)
2018-09-01 04:59:30 +08:00
- result_code (int, success = 0, no such host = 1, ping error = 2)
2018-09-01 04:59:30 +08:00
##### reply_received vs packets_received
2019-09-21 07:49:14 +08:00
On Windows systems with `method = "exec"`, the "Destination net unreachable" reply will increment `packets_received` but not `reply_received`*.
2019-09-21 07:49:14 +08:00
##### ttl
There is currently no support for TTL on windows with `"native"`; track
progress at https://github.com/golang/go/issues/7175 and
https://github.com/golang/go/issues/7174
2018-09-01 04:59:30 +08:00
2019-09-21 07:49:14 +08:00
### Example Output
```
2019-03-09 06:30:38 +08:00
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
2016-12-15 03:47:48 +08:00
```