Skip to content

Commit

Permalink
inputs.ping: Add an option to specify packet size (influxdata#9274)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajiv-k authored May 20, 2021
1 parent e8ae019 commit 8c73370
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugins/inputs/ping/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions plugins/inputs/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 8c73370

Please sign in to comment.