diff --git a/plugins/inputs/ping/README.md b/plugins/inputs/ping/README.md index 82c0d5848..5829d6bd0 100644 --- a/plugins/inputs/ping/README.md +++ b/plugins/inputs/ping/README.md @@ -70,6 +70,10 @@ native Go by the Telegraf process, eliminating the need to execute the system ## Use only IPv6 addresses when resolving a hostname. # 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 ``` #### File Limit diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index c8d768c64..7d3b05178 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -18,6 +18,10 @@ import ( "github.com/influxdata/telegraf/plugins/inputs" ) +const ( + defaultPingDataBytesSize = 56 +) + // HostPinger is a function that runs the "ping" function using a list of // passed arguments. This can be easily switched with a mocked ping function // for unit test purposes (see ping_test.go) @@ -73,6 +77,9 @@ type Ping struct { // Calculate the given percentiles when using native method Percentiles []int + + // Packet size + Size *int } func (*Ping) Description() string { @@ -125,6 +132,10 @@ const sampleConfig = ` ## Use only IPv6 addresses when resolving a hostname. # 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 ` func (*Ping) SampleConfig() string { @@ -172,6 +183,13 @@ func (p *Ping) nativePing(destination string) (*pingStats, error) { pinger.SetNetwork("ip6") } + if p.Method == "native" { + pinger.Size = defaultPingDataBytesSize + if p.Size != nil { + pinger.Size = *p.Size + } + } + pinger.Source = p.sourceAddress pinger.Interval = p.calcInterval