ping plugin: Set default timeout

This commit is contained in:
Cameron Sparr 2016-04-27 15:08:38 -06:00
parent 4de75ce621
commit ee4f4d7800
1 changed files with 9 additions and 9 deletions

View File

@ -43,18 +43,18 @@ func (_ *Ping) Description() string {
return "Ping given url(s) and return statistics" return "Ping given url(s) and return statistics"
} }
var sampleConfig = ` const sampleConfig = `
## NOTE: this plugin forks the ping command. You may need to set capabilities ## NOTE: this plugin forks the ping command. You may need to set capabilities
## via setcap cap_net_raw+p /bin/ping ## via setcap cap_net_raw+p /bin/ping
#
## urls to ping ## urls to ping
urls = ["www.google.com"] # required urls = ["www.google.com"] # required
## number of pings to send (ping -c <COUNT>) ## number of pings to send per collection (ping -c <COUNT>)
count = 1 # required count = 1 # required
## interval, in s, at which to ping. 0 == default (ping -i <PING_INTERVAL>) ## interval, in s, at which to ping. 0 == default (ping -i <PING_INTERVAL>)
ping_interval = 0.0 ping_interval = 0.0
## ping timeout, in s. 0 == no timeout (ping -t <TIMEOUT>) ## ping timeout, in s. 0 == no timeout (ping -W <TIMEOUT>)
timeout = 0.0 timeout = 1.0
## interface to send ping from (ping -I <INTERFACE>) ## interface to send ping from (ping -I <INTERFACE>)
interface = "" interface = ""
` `
@ -71,16 +71,16 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error {
// Spin off a go routine for each url to ping // Spin off a go routine for each url to ping
for _, url := range p.Urls { for _, url := range p.Urls {
wg.Add(1) wg.Add(1)
go func(url string, acc telegraf.Accumulator) { go func(u string) {
defer wg.Done() defer wg.Done()
args := p.args(url) args := p.args(u)
out, err := p.pingHost(args...) out, err := p.pingHost(args...)
if err != nil { if err != nil {
// Combine go err + stderr output // Combine go err + stderr output
errorChannel <- errors.New( errorChannel <- errors.New(
strings.TrimSpace(out) + ", " + err.Error()) strings.TrimSpace(out) + ", " + err.Error())
} }
tags := map[string]string{"url": url} tags := map[string]string{"url": u}
trans, rec, avg, err := processPingOutput(out) trans, rec, avg, err := processPingOutput(out)
if err != nil { if err != nil {
// fatal error // fatal error
@ -98,7 +98,7 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error {
fields["average_response_ms"] = avg fields["average_response_ms"] = avg
} }
acc.AddFields("ping", fields, tags) acc.AddFields("ping", fields, tags)
}(url, acc) }(url)
} }
wg.Wait() wg.Wait()