inputs.ping: Add an option to specify packet size (#9274)

This commit is contained in:
Rajiv Kushwaha 2021-05-21 00:51:20 +05:30 committed by GitHub
parent e8ae01921b
commit 8c73370e50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -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

View File

@ -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