From f2e74b2389dfb80df409a360ea8a52f65fd9e7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sun, 16 Sep 2018 03:28:41 +0900 Subject: [PATCH 01/26] re-order functions --- plugins/inputs/ping/ping_windows.go | 184 ++++++++++++++-------------- 1 file changed, 92 insertions(+), 92 deletions(-) diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index 06a7f590e3325..c9f32badb9daf 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -55,98 +55,6 @@ func (s *Ping) SampleConfig() string { return sampleConfig } -func hostPinger(timeout float64, args ...string) (string, error) { - bin, err := exec.LookPath("ping") - if err != nil { - return "", err - } - c := exec.Command(bin, args...) - out, err := internal.CombinedOutputTimeout(c, - time.Second*time.Duration(timeout+1)) - return string(out), err -} - -// processPingOutput takes in a string output from the ping command -// based on linux implementation but using regex ( multilanguage support ) -// It returns (, , , , , ) -func processPingOutput(out string) (int, int, int, int, int, int, error) { - // So find a line contain 3 numbers except reply lines - var stats, aproxs []string = nil, nil - err := errors.New("Fatal error processing ping output") - stat := regexp.MustCompile(`=\W*(\d+)\D*=\W*(\d+)\D*=\W*(\d+)`) - aprox := regexp.MustCompile(`=\W*(\d+)\D*ms\D*=\W*(\d+)\D*ms\D*=\W*(\d+)\D*ms`) - tttLine := regexp.MustCompile(`TTL=\d+`) - lines := strings.Split(out, "\n") - var receivedReply int = 0 - for _, line := range lines { - if tttLine.MatchString(line) { - receivedReply++ - } else { - if stats == nil { - stats = stat.FindStringSubmatch(line) - } - if stats != nil && aproxs == nil { - aproxs = aprox.FindStringSubmatch(line) - } - } - } - - // stats data should contain 4 members: entireExpression + ( Send, Receive, Lost ) - if len(stats) != 4 { - return 0, 0, 0, -1, -1, -1, err - } - trans, err := strconv.Atoi(stats[1]) - if err != nil { - return 0, 0, 0, -1, -1, -1, err - } - receivedPacket, err := strconv.Atoi(stats[2]) - if err != nil { - return 0, 0, 0, -1, -1, -1, err - } - - // aproxs data should contain 4 members: entireExpression + ( min, max, avg ) - if len(aproxs) != 4 { - return trans, receivedReply, receivedPacket, -1, -1, -1, err - } - min, err := strconv.Atoi(aproxs[1]) - if err != nil { - return trans, receivedReply, receivedPacket, -1, -1, -1, err - } - max, err := strconv.Atoi(aproxs[2]) - if err != nil { - return trans, receivedReply, receivedPacket, -1, -1, -1, err - } - avg, err := strconv.Atoi(aproxs[3]) - if err != nil { - return 0, 0, 0, -1, -1, -1, err - } - - return trans, receivedReply, receivedPacket, avg, min, max, err -} - -func (p *Ping) timeout() float64 { - // According to MSDN, default ping timeout for windows is 4 second - // Add also one second interval - - if p.Timeout > 0 { - return p.Timeout + 1 - } - return 4 + 1 -} - -// args returns the arguments for the 'ping' executable -func (p *Ping) args(url string) []string { - args := []string{"-n", strconv.Itoa(p.Count)} - - if p.Timeout > 0 { - args = append(args, "-w", strconv.FormatFloat(p.Timeout*1000, 'f', 0, 64)) - } - - args = append(args, url) - - return args -} - func (p *Ping) Gather(acc telegraf.Accumulator) error { if p.Count < 1 { p.Count = 1 @@ -229,6 +137,98 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { return errors.New(strings.Join(errorStrings, "\n")) } +func hostPinger(timeout float64, args ...string) (string, error) { + bin, err := exec.LookPath("ping") + if err != nil { + return "", err + } + c := exec.Command(bin, args...) + out, err := internal.CombinedOutputTimeout(c, + time.Second*time.Duration(timeout+1)) + return string(out), err +} + +// args returns the arguments for the 'ping' executable +func (p *Ping) args(url string) []string { + args := []string{"-n", strconv.Itoa(p.Count)} + + if p.Timeout > 0 { + args = append(args, "-w", strconv.FormatFloat(p.Timeout*1000, 'f', 0, 64)) + } + + args = append(args, url) + + return args +} + +// processPingOutput takes in a string output from the ping command +// based on linux implementation but using regex ( multilanguage support ) +// It returns (, , , , , ) +func processPingOutput(out string) (int, int, int, int, int, int, error) { + // So find a line contain 3 numbers except reply lines + var stats, aproxs []string = nil, nil + err := errors.New("Fatal error processing ping output") + stat := regexp.MustCompile(`=\W*(\d+)\D*=\W*(\d+)\D*=\W*(\d+)`) + aprox := regexp.MustCompile(`=\W*(\d+)\D*ms\D*=\W*(\d+)\D*ms\D*=\W*(\d+)\D*ms`) + tttLine := regexp.MustCompile(`TTL=\d+`) + lines := strings.Split(out, "\n") + var receivedReply int = 0 + for _, line := range lines { + if tttLine.MatchString(line) { + receivedReply++ + } else { + if stats == nil { + stats = stat.FindStringSubmatch(line) + } + if stats != nil && aproxs == nil { + aproxs = aprox.FindStringSubmatch(line) + } + } + } + + // stats data should contain 4 members: entireExpression + ( Send, Receive, Lost ) + if len(stats) != 4 { + return 0, 0, 0, -1, -1, -1, err + } + trans, err := strconv.Atoi(stats[1]) + if err != nil { + return 0, 0, 0, -1, -1, -1, err + } + receivedPacket, err := strconv.Atoi(stats[2]) + if err != nil { + return 0, 0, 0, -1, -1, -1, err + } + + // aproxs data should contain 4 members: entireExpression + ( min, max, avg ) + if len(aproxs) != 4 { + return trans, receivedReply, receivedPacket, -1, -1, -1, err + } + min, err := strconv.Atoi(aproxs[1]) + if err != nil { + return trans, receivedReply, receivedPacket, -1, -1, -1, err + } + max, err := strconv.Atoi(aproxs[2]) + if err != nil { + return trans, receivedReply, receivedPacket, -1, -1, -1, err + } + avg, err := strconv.Atoi(aproxs[3]) + if err != nil { + return 0, 0, 0, -1, -1, -1, err + } + + return trans, receivedReply, receivedPacket, avg, min, max, err +} + +func (p *Ping) timeout() float64 { + // According to MSDN, default ping timeout for windows is 4 second + // Add also one second interval + + if p.Timeout > 0 { + return p.Timeout + 1 + } + return 4 + 1 +} + func init() { inputs.Add("ping", func() telegraf.Input { return &Ping{ From 2f783d60a7bd4d271b32fa81db019833da941557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sun, 16 Sep 2018 03:42:21 +0900 Subject: [PATCH 02/26] do same error handling logic between linux and windows --- plugins/inputs/ping/ping.go | 191 ++++++++++++++-------------- plugins/inputs/ping/ping_windows.go | 130 +++++++++---------- 2 files changed, 164 insertions(+), 157 deletions(-) diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index 430cbe6d4242e..059bbf9e0a91d 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -43,6 +43,9 @@ type Ping struct { // URLs to ping Urls []string + // URLs to ping ipv6 address + UrlsV6 []string `toml:urls_v6` + // host ping function pingHost HostPinger } @@ -55,6 +58,9 @@ const sampleConfig = ` ## List of urls to ping urls = ["example.org"] + ## List of urls to ping with ipv6 protocol + urls_v6 = ["example.org"] + ## Number of pings to send per collection (ping -c ) # count = 1 @@ -78,146 +84,147 @@ func (_ *Ping) SampleConfig() string { } func (p *Ping) Gather(acc telegraf.Accumulator) error { - var wg sync.WaitGroup // Spin off a go routine for each url to ping for _, url := range p.Urls { wg.Add(1) - go func(u string) { - defer wg.Done() - tags := map[string]string{"url": u} - fields := map[string]interface{}{"result_code": 0} + p.pingToURL(url, wg, acc) + } - _, err := net.LookupHost(u) - if err != nil { - acc.AddError(err) - fields["result_code"] = 1 - acc.AddFields("ping", fields, tags) - return - } + wg.wait() - args := p.args(u, runtime.GOOS) - totalTimeout := float64(p.Count)*p.Timeout + float64(p.Count-1)*p.PingInterval + return nil +} - out, err := p.pingHost(totalTimeout, args...) - if err != nil { - // Some implementations of ping return a 1 exit code on - // timeout, if this occurs we will not exit and try to parse - // the output. - status := -1 - if exitError, ok := err.(*exec.ExitError); ok { - if ws, ok := exitError.Sys().(syscall.WaitStatus); ok { - status = ws.ExitStatus() - } - } +func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) { + defer wg.Done() + tags := map[string]string{"url": u} + fields := map[string]interface{}{"result_code": 0} - if status != 1 { - // Combine go err + stderr output - out = strings.TrimSpace(out) - if len(out) > 0 { - acc.AddError(fmt.Errorf("host %s: %s, %s", u, out, err)) - } else { - acc.AddError(fmt.Errorf("host %s: %s", u, err)) - } - fields["result_code"] = 2 - acc.AddFields("ping", fields, tags) - return - } - } + _, err := net.LookupHost(u) + if err != nil { + acc.AddError(err) + fields["result_code"] = 1 + acc.AddFields("ping", fields, tags) + return + } - trans, rec, min, avg, max, stddev, err := processPingOutput(out) - if err != nil { - // fatal error - acc.AddError(fmt.Errorf("%s: %s", err, u)) - fields["result_code"] = 2 - acc.AddFields("ping", fields, tags) - return - } - // Calculate packet loss percentage - loss := float64(trans-rec) / float64(trans) * 100.0 - fields["packets_transmitted"] = trans - fields["packets_received"] = rec - fields["percent_packet_loss"] = loss - if min >= 0 { - fields["minimum_response_ms"] = min - } - if avg >= 0 { - fields["average_response_ms"] = avg - } - if max >= 0 { - fields["maximum_response_ms"] = max + args := p.args(u, runtime.GOOS) + totalTimeout := float64(p.Count)*p.Timeout + float64(p.Count-1)*p.PingInterval + + out, err := p.pingHost(totalTimeout, args...) + if err != nil { + // Some implementations of ping return a 1 exit code on + // timeout, if this occurs we will not exit and try to parse + // the output. + status := -1 + if exitError, ok := err.(*exec.ExitError); ok { + if ws, ok := exitError.Sys().(syscall.WaitStatus); ok { + status = ws.ExitStatus() } - if stddev >= 0 { - fields["standard_deviation_ms"] = stddev + } + + if status != 1 { + // Combine go err + stderr output + out = strings.TrimSpace(out) + if len(out) > 0 { + acc.AddError(fmt.Errorf("host %s: %s, %s", u, out, err)) + } else { + acc.AddError(fmt.Errorf("host %s: %s", u, err)) } + fields["result_code"] = 2 acc.AddFields("ping", fields, tags) - }(url) + return + } } - wg.Wait() - - return nil + trans, rec, min, avg, max, stddev, err := processPingOutput(out) + if err != nil { + // fatal error + acc.AddError(fmt.Errorf("%s: %s", err, u)) + fields["result_code"] = 2 + acc.AddFields("ping", fields, tags) + return + } + // Calculate packet loss percentage + loss := float64(trans-rec) / float64(trans) * 100.0 + fields["packets_transmitted"] = trans + fields["packets_received"] = rec + fields["percent_packet_loss"] = loss + if min >= 0 { + fields["minimum_response_ms"] = min + } + if avg >= 0 { + fields["average_response_ms"] = avg + } + if max >= 0 { + fields["maximum_response_ms"] = max + } + if stddev >= 0 { + fields["standard_deviation_ms"] = stddev + } + acc.AddFields("ping", fields, tags) } -func hostPinger(timeout float64, args ...string) (string, error) { - bin, err := exec.LookPath("ping") +func hostpinger(timeout float64, args ...string) (string, error) { + bin, err := exec.lookpath("ping") if err != nil { return "", err } - c := exec.Command(bin, args...) - out, err := internal.CombinedOutputTimeout(c, - time.Second*time.Duration(timeout+5)) + c := exec.command(bin, args...) + out, err := internal.combinedoutputtimeout(c, + time.second*time.duration(timeout+5)) return string(out), err } // args returns the arguments for the 'ping' executable -func (p *Ping) args(url string, system string) []string { - // Build the ping command args based on toml config - args := []string{"-c", strconv.Itoa(p.Count), "-n", "-s", "16"} - if p.PingInterval > 0 { - args = append(args, "-i", strconv.FormatFloat(p.PingInterval, 'f', -1, 64)) +func (p *ping) args(url string, system string) []string { + // build the ping command args based on toml config + args := []string{"-c", strconv.itoa(p.count), "-n", "-s", "16"} + if p.pinginterval > 0 { + args = append(args, "-i", strconv.formatfloat(p.pinginterval, 'f', -1, 64)) } - if p.Timeout > 0 { + if p.timeout > 0 { switch system { case "darwin", "freebsd", "netbsd", "openbsd": - args = append(args, "-W", strconv.FormatFloat(p.Timeout*1000, 'f', -1, 64)) + args = append(args, "-w", strconv.formatfloat(p.timeout*1000, 'f', -1, 64)) case "linux": - args = append(args, "-W", strconv.FormatFloat(p.Timeout, 'f', -1, 64)) + args = append(args, "-w", strconv.formatfloat(p.timeout, 'f', -1, 64)) default: - // Not sure the best option here, just assume GNU ping? - args = append(args, "-W", strconv.FormatFloat(p.Timeout, 'f', -1, 64)) + // not sure the best option here, just assume gnu ping? + args = append(args, "-w", strconv.formatfloat(p.timeout, 'f', -1, 64)) } } - if p.Deadline > 0 { + if p.deadline > 0 { switch system { case "darwin", "freebsd", "netbsd", "openbsd": - args = append(args, "-t", strconv.Itoa(p.Deadline)) + args = append(args, "-t", strconv.itoa(p.deadline)) case "linux": - args = append(args, "-w", strconv.Itoa(p.Deadline)) + args = append(args, "-w", strconv.itoa(p.deadline)) default: - // Not sure the best option here, just assume GNU ping? - args = append(args, "-w", strconv.Itoa(p.Deadline)) + // not sure the best option here, just assume gnu ping? + args = append(args, "-w", strconv.itoa(p.deadline)) } } - if p.Interface != "" { + if p.interface != "" { switch system { case "darwin", "freebsd", "netbsd", "openbsd": - args = append(args, "-S", p.Interface) + args = append(args, "-s", p.interface) case "linux": - args = append(args, "-I", p.Interface) + args = append(args, "-i", p.interface) default: - // Not sure the best option here, just assume GNU ping? - args = append(args, "-I", p.Interface) + // not sure the best option here, just assume gnu ping? + args = append(args, "-i", p.interface) } } args = append(args, url) return args } -// processPingOutput takes in a string output from the ping command, like: +// processpingoutput takes in a string output from the ping command, like: // -// PING www.google.com (173.194.115.84): 56 data bytes +// ping www.google.com (173.194.115.84): 56 data bytes // 64 bytes from 173.194.115.84: icmp_seq=0 ttl=54 time=52.172 ms // 64 bytes from 173.194.115.84: icmp_seq=1 ttl=54 time=34.843 ms // diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index c9f32badb9daf..677e23a9bbe13 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -4,6 +4,7 @@ package ping import ( "errors" + "fmt" "net" "os/exec" "regexp" @@ -32,6 +33,9 @@ type Ping struct { // URLs to ping Urls []string + // URLs to ping ipv6 address + UrlsV6 []string `toml:urls_v6` + // host ping function pingHost HostPinger } @@ -44,6 +48,9 @@ const sampleConfig = ` ## List of urls to ping urls = ["www.google.com"] + ## List of urls to ping with ipv6 protocol + urls_v6 = ["www.google.com"] + ## number of pings to send per collection (ping -n ) # count = 1 @@ -60,81 +67,74 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { p.Count = 1 } var wg sync.WaitGroup - errorChannel := make(chan error, len(p.Urls)*2) - var pendingError error = nil + // Spin off a go routine for each url to ping for _, url := range p.Urls { wg.Add(1) - go func(u string) { - defer wg.Done() - - tags := map[string]string{"url": u} - fields := map[string]interface{}{"result_code": 0} - - _, err := net.LookupHost(u) - if err != nil { - errorChannel <- err - fields["result_code"] = 1 - acc.AddFields("ping", fields, tags) - return - } - - args := p.args(u) - totalTimeout := p.timeout() * float64(p.Count) - out, err := p.pingHost(totalTimeout, args...) - // ping host return exitcode != 0 also when there was no response from host - // but command was execute successfully - if err != nil { - // Combine go err + stderr output - pendingError = errors.New(strings.TrimSpace(out) + ", " + err.Error()) - } - trans, recReply, receivePacket, avg, min, max, err := processPingOutput(out) - if err != nil { - // fatal error - if pendingError != nil { - errorChannel <- pendingError - } - errorChannel <- err - - fields["errors"] = 100.0 - acc.AddFields("ping", fields, tags) - return - } - // Calculate packet loss percentage - lossReply := float64(trans-recReply) / float64(trans) * 100.0 - lossPackets := float64(trans-receivePacket) / float64(trans) * 100.0 - - fields["packets_transmitted"] = trans - fields["reply_received"] = recReply - fields["packets_received"] = receivePacket - fields["percent_packet_loss"] = lossPackets - fields["percent_reply_loss"] = lossReply - if avg >= 0 { - fields["average_response_ms"] = float64(avg) - } - if min >= 0 { - fields["minimum_response_ms"] = float64(min) - } - if max >= 0 { - fields["maximum_response_ms"] = float64(max) - } - acc.AddFields("ping", fields, tags) - }(url) + p.pingToURL(url, wg, acc) } wg.Wait() - close(errorChannel) - // Get all errors and return them as one giant error - errorStrings := []string{} - for err := range errorChannel { - errorStrings = append(errorStrings, err.Error()) + return nil +} + +func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) { + defer wg.Done() + + tags := map[string]string{"url": u} + fields := map[string]interface{}{"result_code": 0} + + _, err := net.LookupHost(u) + if err != nil { + acc.AddError(err) + fields["result_code"] = 1 + acc.AddFields("ping", fields, tags) + return + } + + args := p.args(u) + totalTimeout := p.timeout() * float64(p.Count) + out, err := p.pingHost(totalTimeout, args...) + // ping host return exitcode != 0 also when there was no response from host + // but command was execute successfully + if err != nil { + // Combine go err + stderr output + pendingError = errors.New(strings.TrimSpace(out) + ", " + err.Error()) } + trans, recReply, receivePacket, avg, min, max, err := processPingOutput(out) + if err != nil { + // fatal error + if pendingError != nil { + acc.AddError(fmt.Errorf("%s: %s", pendingError, u)) + } else { + acc.AddError(fmt.Errorf("%s: %s", err, u)) + } - if len(errorStrings) == 0 { - return nil + fields["result_code"] = 2 + fields["errors"] = 100.0 + acc.AddFields("ping", fields, tags) + return + } + // Calculate packet loss percentage + lossReply := float64(trans-recReply) / float64(trans) * 100.0 + lossPackets := float64(trans-receivePacket) / float64(trans) * 100.0 + + fields["packets_transmitted"] = trans + fields["reply_received"] = recReply + fields["packets_received"] = receivePacket + fields["percent_packet_loss"] = lossPackets + fields["percent_reply_loss"] = lossReply + if avg >= 0 { + fields["average_response_ms"] = float64(avg) + } + if min >= 0 { + fields["minimum_response_ms"] = float64(min) + } + if max >= 0 { + fields["maximum_response_ms"] = float64(max) } - return errors.New(strings.Join(errorStrings, "\n")) + acc.AddFields("ping", fields, tags) } func hostPinger(timeout float64, args ...string) (string, error) { From 19461bad474899c8909593c7768d48b87c580f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sun, 16 Sep 2018 03:48:38 +0900 Subject: [PATCH 03/26] add support ipv6 ping --- plugins/inputs/ping/ping.go | 21 +++++++++++++++------ plugins/inputs/ping/ping_windows.go | 21 +++++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index 059bbf9e0a91d..c4fd27dbe59cf 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -22,7 +22,7 @@ import ( // 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) -type HostPinger func(timeout float64, args ...string) (string, error) +type HostPinger func(timeout float64, isV6 bool, args ...string) (string, error) type Ping struct { // Interval at which to ping (ping -i ) @@ -89,7 +89,11 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { // Spin off a go routine for each url to ping for _, url := range p.Urls { wg.Add(1) - p.pingToURL(url, wg, acc) + go p.pingToURL(url, false, wg, acc) + } + for _, url := range p.UrlsV6 { + wg.Add(1) + go p.pingToURL(url, true, wg, acc) } wg.wait() @@ -97,7 +101,7 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { return nil } -func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) { +func (p *Ping) pingToURL(u string, isV6 bool, wg sync.WaitGroup, acc telegraf.Accumulator) { defer wg.Done() tags := map[string]string{"url": u} fields := map[string]interface{}{"result_code": 0} @@ -113,7 +117,7 @@ func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) args := p.args(u, runtime.GOOS) totalTimeout := float64(p.Count)*p.Timeout + float64(p.Count-1)*p.PingInterval - out, err := p.pingHost(totalTimeout, args...) + out, err := p.pingHost(totalTimeout, isV6, args...) if err != nil { // Some implementations of ping return a 1 exit code on // timeout, if this occurs we will not exit and try to parse @@ -167,8 +171,13 @@ func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) acc.AddFields("ping", fields, tags) } -func hostpinger(timeout float64, args ...string) (string, error) { - bin, err := exec.lookpath("ping") +func hostPinger(timeout float64, isV6 bool, args ...string) (string, error) { + pingCmd := "ping" + if isV6 == true { + pingCmd = "ping6" + } + + bin, err := exec.lookpath(pingCmd) if err != nil { return "", err } diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index 677e23a9bbe13..f32261240e77f 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -21,7 +21,7 @@ import ( // 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) -type HostPinger func(timeout float64, args ...string) (string, error) +type HostPinger func(timeout float64, isV6 bool, args ...string) (string, error) type Ping struct { // Number of pings to send (ping -c ) @@ -71,7 +71,11 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { // Spin off a go routine for each url to ping for _, url := range p.Urls { wg.Add(1) - p.pingToURL(url, wg, acc) + go p.pingToURL(url, false, wg, acc) + } + for _, url := range p.UrlsV6 { + wg.Add(1) + go p.pingToURL(url, true, wg, acc) } wg.Wait() @@ -79,7 +83,7 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { return nil } -func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) { +func (p *Ping) pingToURL(u string, isV6 bool, wg sync.WaitGroup, acc telegraf.Accumulator) { defer wg.Done() tags := map[string]string{"url": u} @@ -95,7 +99,7 @@ func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) args := p.args(u) totalTimeout := p.timeout() * float64(p.Count) - out, err := p.pingHost(totalTimeout, args...) + out, err := p.pingHost(totalTimeout, isV6, args...) // ping host return exitcode != 0 also when there was no response from host // but command was execute successfully if err != nil { @@ -137,8 +141,13 @@ func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) acc.AddFields("ping", fields, tags) } -func hostPinger(timeout float64, args ...string) (string, error) { - bin, err := exec.LookPath("ping") +func hostPinger(timeout float64, isV6 bool, args ...string) (string, error) { + pingCmd := "ping" + if isV6 == true { + pingCmd = "ping6" + } + + bin, err := exec.LookPath(pingCmd) if err != nil { return "", err } From 09bef984151b730ffb450a7399a4f03053240c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sun, 16 Sep 2018 03:52:35 +0900 Subject: [PATCH 04/26] edit README.md --- plugins/inputs/ping/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/inputs/ping/README.md b/plugins/inputs/ping/README.md index 4996fdc37bf9f..a76e5723cdead 100644 --- a/plugins/inputs/ping/README.md +++ b/plugins/inputs/ping/README.md @@ -15,6 +15,9 @@ apt-get install iputils-ping ## List of urls to ping urls = ["example.org"] + ## List of urls to ping to ipv6 address + urls_v6 = ["example.org"] + ## Number of pings to send per collection (ping -c ) # count = 1 From 4c556c1087d1bb10444045e2b969b5aa0e095ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sun, 16 Sep 2018 04:56:14 +0900 Subject: [PATCH 05/26] fix typing error --- plugins/inputs/ping/ping.go | 58 ++++++++++++++--------------- plugins/inputs/ping/ping_test.go | 10 ++--- plugins/inputs/ping/ping_windows.go | 8 ++-- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index c4fd27dbe59cf..9b80132e4a897 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -44,7 +44,7 @@ type Ping struct { Urls []string // URLs to ping ipv6 address - UrlsV6 []string `toml:urls_v6` + UrlsV6 []string `toml:"urls_v6"` // host ping function pingHost HostPinger @@ -89,19 +89,19 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { // Spin off a go routine for each url to ping for _, url := range p.Urls { wg.Add(1) - go p.pingToURL(url, false, wg, acc) + go p.pingToURL(url, false, &wg, acc) } for _, url := range p.UrlsV6 { wg.Add(1) - go p.pingToURL(url, true, wg, acc) + go p.pingToURL(url, true, &wg, acc) } - wg.wait() + wg.Wait() return nil } -func (p *Ping) pingToURL(u string, isV6 bool, wg sync.WaitGroup, acc telegraf.Accumulator) { +func (p *Ping) pingToURL(u string, isV6 bool, wg *sync.WaitGroup, acc telegraf.Accumulator) { defer wg.Done() tags := map[string]string{"url": u} fields := map[string]interface{}{"result_code": 0} @@ -177,54 +177,54 @@ func hostPinger(timeout float64, isV6 bool, args ...string) (string, error) { pingCmd = "ping6" } - bin, err := exec.lookpath(pingCmd) + bin, err := exec.LookPath(pingCmd) if err != nil { return "", err } - c := exec.command(bin, args...) - out, err := internal.combinedoutputtimeout(c, - time.second*time.duration(timeout+5)) + c := exec.Command(bin, args...) + out, err := internal.CombinedOutputTimeout(c, + time.Second*time.Duration(timeout+5)) return string(out), err } // args returns the arguments for the 'ping' executable -func (p *ping) args(url string, system string) []string { - // build the ping command args based on toml config - args := []string{"-c", strconv.itoa(p.count), "-n", "-s", "16"} - if p.pinginterval > 0 { - args = append(args, "-i", strconv.formatfloat(p.pinginterval, 'f', -1, 64)) +func (p *Ping) args(url string, system string) []string { + // Build the ping command args based on toml config + args := []string{"-c", strconv.Itoa(p.Count), "-n", "-s", "16"} + if p.PingInterval > 0 { + args = append(args, "-i", strconv.FormatFloat(p.PingInterval, 'f', -1, 64)) } - if p.timeout > 0 { + if p.Timeout > 0 { switch system { case "darwin", "freebsd", "netbsd", "openbsd": - args = append(args, "-w", strconv.formatfloat(p.timeout*1000, 'f', -1, 64)) + args = append(args, "-W", strconv.FormatFloat(p.Timeout*1000, 'f', -1, 64)) case "linux": - args = append(args, "-w", strconv.formatfloat(p.timeout, 'f', -1, 64)) + args = append(args, "-W", strconv.FormatFloat(p.Timeout, 'f', -1, 64)) default: - // not sure the best option here, just assume gnu ping? - args = append(args, "-w", strconv.formatfloat(p.timeout, 'f', -1, 64)) + // Not sure the best option here, just assume GNU ping? + args = append(args, "-W", strconv.FormatFloat(p.Timeout, 'f', -1, 64)) } } - if p.deadline > 0 { + if p.Deadline > 0 { switch system { case "darwin", "freebsd", "netbsd", "openbsd": - args = append(args, "-t", strconv.itoa(p.deadline)) + args = append(args, "-t", strconv.Itoa(p.Deadline)) case "linux": - args = append(args, "-w", strconv.itoa(p.deadline)) + args = append(args, "-w", strconv.Itoa(p.Deadline)) default: - // not sure the best option here, just assume gnu ping? - args = append(args, "-w", strconv.itoa(p.deadline)) + // Not sure the best option here, just assume GNU ping? + args = append(args, "-w", strconv.Itoa(p.Deadline)) } } - if p.interface != "" { + if p.Interface != "" { switch system { case "darwin", "freebsd", "netbsd", "openbsd": - args = append(args, "-s", p.interface) + args = append(args, "-S", p.Interface) case "linux": - args = append(args, "-i", p.interface) + args = append(args, "-I", p.Interface) default: - // not sure the best option here, just assume gnu ping? - args = append(args, "-i", p.interface) + // Not sure the best option here, just assume GNU ping? + args = append(args, "-I", p.Interface) } } args = append(args, url) diff --git a/plugins/inputs/ping/ping_test.go b/plugins/inputs/ping/ping_test.go index d5b82608aadd3..61235e250c394 100644 --- a/plugins/inputs/ping/ping_test.go +++ b/plugins/inputs/ping/ping_test.go @@ -124,7 +124,7 @@ func TestArgs(t *testing.T) { } } -func mockHostPinger(timeout float64, args ...string) (string, error) { +func mockHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { return linuxPingOutput, nil } @@ -165,7 +165,7 @@ PING www.google.com (216.58.218.164) 56(84) bytes of data. rtt min/avg/max/mdev = 35.225/44.033/51.806/5.325 ms ` -func mockLossyHostPinger(timeout float64, args ...string) (string, error) { +func mockLossyHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { return lossyPingOutput, nil } @@ -200,7 +200,7 @@ Request timeout for icmp_seq 0 2 packets transmitted, 0 packets received, 100.0% packet loss ` -func mockErrorHostPinger(timeout float64, args ...string) (string, error) { +func mockErrorHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { // This error will not trigger correct error paths return errorPingOutput, nil } @@ -225,7 +225,7 @@ func TestBadPingGather(t *testing.T) { acc.AssertContainsTaggedFields(t, "ping", fields, tags) } -func mockFatalHostPinger(timeout float64, args ...string) (string, error) { +func mockFatalHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { return fatalPingOutput, errors.New("So very bad") } @@ -265,7 +265,7 @@ func TestErrorWithHostNamePingGather(t *testing.T) { var acc testutil.Accumulator p := Ping{ Urls: []string{"www.amazon.com"}, - pingHost: func(timeout float64, args ...string) (string, error) { + pingHost: func(timeout float64, isV6 bool, args ...string) (string, error) { return param.out, errors.New("So very bad") }, } diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index f32261240e77f..1ff2aee00031e 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -34,7 +34,7 @@ type Ping struct { Urls []string // URLs to ping ipv6 address - UrlsV6 []string `toml:urls_v6` + UrlsV6 []string `toml:"urls_v6"` // host ping function pingHost HostPinger @@ -71,11 +71,11 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { // Spin off a go routine for each url to ping for _, url := range p.Urls { wg.Add(1) - go p.pingToURL(url, false, wg, acc) + go p.pingToURL(url, false, &wg, acc) } for _, url := range p.UrlsV6 { wg.Add(1) - go p.pingToURL(url, true, wg, acc) + go p.pingToURL(url, true, &wg, acc) } wg.Wait() @@ -83,7 +83,7 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { return nil } -func (p *Ping) pingToURL(u string, isV6 bool, wg sync.WaitGroup, acc telegraf.Accumulator) { +func (p *Ping) pingToURL(u string, isV6 bool, wg *sync.WaitGroup, acc telegraf.Accumulator) { defer wg.Done() tags := map[string]string{"url": u} From 73520390f78fe270a7f69dd6065198fdf70cfbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sun, 16 Sep 2018 06:06:41 +0900 Subject: [PATCH 06/26] fix typing error --- plugins/inputs/ping/ping_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index 1ff2aee00031e..04876b6063e82 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -104,7 +104,7 @@ func (p *Ping) pingToURL(u string, isV6 bool, wg *sync.WaitGroup, acc telegraf.A // but command was execute successfully if err != nil { // Combine go err + stderr output - pendingError = errors.New(strings.TrimSpace(out) + ", " + err.Error()) + pendingError := errors.New(strings.TrimSpace(out) + ", " + err.Error()) } trans, recReply, receivePacket, avg, min, max, err := processPingOutput(out) if err != nil { From 07f664b1264b5ec03b44c7a5eb440669d830c663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sun, 16 Sep 2018 11:11:16 +0900 Subject: [PATCH 07/26] fix typing error --- plugins/inputs/ping/ping_windows.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index 04876b6063e82..09c91f2c965da 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -102,9 +102,10 @@ func (p *Ping) pingToURL(u string, isV6 bool, wg *sync.WaitGroup, acc telegraf.A out, err := p.pingHost(totalTimeout, isV6, args...) // ping host return exitcode != 0 also when there was no response from host // but command was execute successfully + var pendingError error if err != nil { // Combine go err + stderr output - pendingError := errors.New(strings.TrimSpace(out) + ", " + err.Error()) + pendingError = errors.New(strings.TrimSpace(out) + ", " + err.Error()) } trans, recReply, receivePacket, avg, min, max, err := processPingOutput(out) if err != nil { From 36fde3ef5a1d42c838b1a2ba9e01e49fae38a6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sun, 16 Sep 2018 11:29:05 +0900 Subject: [PATCH 08/26] fix test error --- plugins/inputs/ping/ping_windows_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/inputs/ping/ping_windows_test.go b/plugins/inputs/ping/ping_windows_test.go index 178e42fcb56dd..27febe9c8c21f 100644 --- a/plugins/inputs/ping/ping_windows_test.go +++ b/plugins/inputs/ping/ping_windows_test.go @@ -59,7 +59,7 @@ func TestHost(t *testing.T) { assert.Equal(t, 52, max, "Max 52") } -func mockHostPinger(timeout float64, args ...string) (string, error) { +func mockHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { return winENPingOutput, nil } @@ -102,7 +102,7 @@ Statystyka badania ping dla 195.187.242.157: (100% straty), ` -func mockErrorHostPinger(timeout float64, args ...string) (string, error) { +func mockErrorHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { return errorPingOutput, errors.New("No packets received") } @@ -147,7 +147,7 @@ Szacunkowy czas błądzenia pakietów w millisekundach: Minimum = 114 ms, Maksimum = 119 ms, Czas średni = 115 ms ` -func mockLossyHostPinger(timeout float64, args ...string) (string, error) { +func mockLossyHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { return lossyPingOutput, nil } @@ -207,7 +207,7 @@ Options: ` -func mockFatalHostPinger(timeout float64, args ...string) (string, error) { +func mockFatalHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { return fatalPingOutput, errors.New("So very bad") } @@ -249,7 +249,7 @@ Ping statistics for 8.8.8.8: Packets: Sent = 4, Received = 1, Lost = 3 (75% loss), ` -func mockUnreachableHostPinger(timeout float64, args ...string) (string, error) { +func mockUnreachableHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { return UnreachablePingOutput, errors.New("So very bad") } @@ -298,7 +298,7 @@ Ping statistics for 8.8.8.8: Packets: Sent = 4, Received = 1, Lost = 3 (75% loss), ` -func mockTTLExpiredPinger(timeout float64, args ...string) (string, error) { +func mockTTLExpiredPinger(timeout float64, isV6 bool, args ...string) (string, error) { return TTLExpiredPingOutput, errors.New("So very bad") } From efd6c962c3df5cde68c0d1293d432f640812b66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sat, 22 Sep 2018 00:48:18 +0900 Subject: [PATCH 09/26] Revert "fix test error" This reverts commit 36fde3ef5a1d42c838b1a2ba9e01e49fae38a6fc. --- plugins/inputs/ping/ping_windows_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/inputs/ping/ping_windows_test.go b/plugins/inputs/ping/ping_windows_test.go index 27febe9c8c21f..178e42fcb56dd 100644 --- a/plugins/inputs/ping/ping_windows_test.go +++ b/plugins/inputs/ping/ping_windows_test.go @@ -59,7 +59,7 @@ func TestHost(t *testing.T) { assert.Equal(t, 52, max, "Max 52") } -func mockHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { +func mockHostPinger(timeout float64, args ...string) (string, error) { return winENPingOutput, nil } @@ -102,7 +102,7 @@ Statystyka badania ping dla 195.187.242.157: (100% straty), ` -func mockErrorHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { +func mockErrorHostPinger(timeout float64, args ...string) (string, error) { return errorPingOutput, errors.New("No packets received") } @@ -147,7 +147,7 @@ Szacunkowy czas błądzenia pakietów w millisekundach: Minimum = 114 ms, Maksimum = 119 ms, Czas średni = 115 ms ` -func mockLossyHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { +func mockLossyHostPinger(timeout float64, args ...string) (string, error) { return lossyPingOutput, nil } @@ -207,7 +207,7 @@ Options: ` -func mockFatalHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { +func mockFatalHostPinger(timeout float64, args ...string) (string, error) { return fatalPingOutput, errors.New("So very bad") } @@ -249,7 +249,7 @@ Ping statistics for 8.8.8.8: Packets: Sent = 4, Received = 1, Lost = 3 (75% loss), ` -func mockUnreachableHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { +func mockUnreachableHostPinger(timeout float64, args ...string) (string, error) { return UnreachablePingOutput, errors.New("So very bad") } @@ -298,7 +298,7 @@ Ping statistics for 8.8.8.8: Packets: Sent = 4, Received = 1, Lost = 3 (75% loss), ` -func mockTTLExpiredPinger(timeout float64, isV6 bool, args ...string) (string, error) { +func mockTTLExpiredPinger(timeout float64, args ...string) (string, error) { return TTLExpiredPingOutput, errors.New("So very bad") } From 2fb3b6409f686e329d29e25423a9ffe63ce422e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sat, 22 Sep 2018 00:48:44 +0900 Subject: [PATCH 10/26] Revert "fix typing error" This reverts commit 4c556c1087d1bb10444045e2b969b5aa0e095ab3. --- plugins/inputs/ping/ping.go | 58 ++++++++++++++--------------- plugins/inputs/ping/ping_test.go | 10 ++--- plugins/inputs/ping/ping_windows.go | 8 ++-- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index 9b80132e4a897..c4fd27dbe59cf 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -44,7 +44,7 @@ type Ping struct { Urls []string // URLs to ping ipv6 address - UrlsV6 []string `toml:"urls_v6"` + UrlsV6 []string `toml:urls_v6` // host ping function pingHost HostPinger @@ -89,19 +89,19 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { // Spin off a go routine for each url to ping for _, url := range p.Urls { wg.Add(1) - go p.pingToURL(url, false, &wg, acc) + go p.pingToURL(url, false, wg, acc) } for _, url := range p.UrlsV6 { wg.Add(1) - go p.pingToURL(url, true, &wg, acc) + go p.pingToURL(url, true, wg, acc) } - wg.Wait() + wg.wait() return nil } -func (p *Ping) pingToURL(u string, isV6 bool, wg *sync.WaitGroup, acc telegraf.Accumulator) { +func (p *Ping) pingToURL(u string, isV6 bool, wg sync.WaitGroup, acc telegraf.Accumulator) { defer wg.Done() tags := map[string]string{"url": u} fields := map[string]interface{}{"result_code": 0} @@ -177,54 +177,54 @@ func hostPinger(timeout float64, isV6 bool, args ...string) (string, error) { pingCmd = "ping6" } - bin, err := exec.LookPath(pingCmd) + bin, err := exec.lookpath(pingCmd) if err != nil { return "", err } - c := exec.Command(bin, args...) - out, err := internal.CombinedOutputTimeout(c, - time.Second*time.Duration(timeout+5)) + c := exec.command(bin, args...) + out, err := internal.combinedoutputtimeout(c, + time.second*time.duration(timeout+5)) return string(out), err } // args returns the arguments for the 'ping' executable -func (p *Ping) args(url string, system string) []string { - // Build the ping command args based on toml config - args := []string{"-c", strconv.Itoa(p.Count), "-n", "-s", "16"} - if p.PingInterval > 0 { - args = append(args, "-i", strconv.FormatFloat(p.PingInterval, 'f', -1, 64)) +func (p *ping) args(url string, system string) []string { + // build the ping command args based on toml config + args := []string{"-c", strconv.itoa(p.count), "-n", "-s", "16"} + if p.pinginterval > 0 { + args = append(args, "-i", strconv.formatfloat(p.pinginterval, 'f', -1, 64)) } - if p.Timeout > 0 { + if p.timeout > 0 { switch system { case "darwin", "freebsd", "netbsd", "openbsd": - args = append(args, "-W", strconv.FormatFloat(p.Timeout*1000, 'f', -1, 64)) + args = append(args, "-w", strconv.formatfloat(p.timeout*1000, 'f', -1, 64)) case "linux": - args = append(args, "-W", strconv.FormatFloat(p.Timeout, 'f', -1, 64)) + args = append(args, "-w", strconv.formatfloat(p.timeout, 'f', -1, 64)) default: - // Not sure the best option here, just assume GNU ping? - args = append(args, "-W", strconv.FormatFloat(p.Timeout, 'f', -1, 64)) + // not sure the best option here, just assume gnu ping? + args = append(args, "-w", strconv.formatfloat(p.timeout, 'f', -1, 64)) } } - if p.Deadline > 0 { + if p.deadline > 0 { switch system { case "darwin", "freebsd", "netbsd", "openbsd": - args = append(args, "-t", strconv.Itoa(p.Deadline)) + args = append(args, "-t", strconv.itoa(p.deadline)) case "linux": - args = append(args, "-w", strconv.Itoa(p.Deadline)) + args = append(args, "-w", strconv.itoa(p.deadline)) default: - // Not sure the best option here, just assume GNU ping? - args = append(args, "-w", strconv.Itoa(p.Deadline)) + // not sure the best option here, just assume gnu ping? + args = append(args, "-w", strconv.itoa(p.deadline)) } } - if p.Interface != "" { + if p.interface != "" { switch system { case "darwin", "freebsd", "netbsd", "openbsd": - args = append(args, "-S", p.Interface) + args = append(args, "-s", p.interface) case "linux": - args = append(args, "-I", p.Interface) + args = append(args, "-i", p.interface) default: - // Not sure the best option here, just assume GNU ping? - args = append(args, "-I", p.Interface) + // not sure the best option here, just assume gnu ping? + args = append(args, "-i", p.interface) } } args = append(args, url) diff --git a/plugins/inputs/ping/ping_test.go b/plugins/inputs/ping/ping_test.go index 61235e250c394..d5b82608aadd3 100644 --- a/plugins/inputs/ping/ping_test.go +++ b/plugins/inputs/ping/ping_test.go @@ -124,7 +124,7 @@ func TestArgs(t *testing.T) { } } -func mockHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { +func mockHostPinger(timeout float64, args ...string) (string, error) { return linuxPingOutput, nil } @@ -165,7 +165,7 @@ PING www.google.com (216.58.218.164) 56(84) bytes of data. rtt min/avg/max/mdev = 35.225/44.033/51.806/5.325 ms ` -func mockLossyHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { +func mockLossyHostPinger(timeout float64, args ...string) (string, error) { return lossyPingOutput, nil } @@ -200,7 +200,7 @@ Request timeout for icmp_seq 0 2 packets transmitted, 0 packets received, 100.0% packet loss ` -func mockErrorHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { +func mockErrorHostPinger(timeout float64, args ...string) (string, error) { // This error will not trigger correct error paths return errorPingOutput, nil } @@ -225,7 +225,7 @@ func TestBadPingGather(t *testing.T) { acc.AssertContainsTaggedFields(t, "ping", fields, tags) } -func mockFatalHostPinger(timeout float64, isV6 bool, args ...string) (string, error) { +func mockFatalHostPinger(timeout float64, args ...string) (string, error) { return fatalPingOutput, errors.New("So very bad") } @@ -265,7 +265,7 @@ func TestErrorWithHostNamePingGather(t *testing.T) { var acc testutil.Accumulator p := Ping{ Urls: []string{"www.amazon.com"}, - pingHost: func(timeout float64, isV6 bool, args ...string) (string, error) { + pingHost: func(timeout float64, args ...string) (string, error) { return param.out, errors.New("So very bad") }, } diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index 09c91f2c965da..fcbe7192d6eeb 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -34,7 +34,7 @@ type Ping struct { Urls []string // URLs to ping ipv6 address - UrlsV6 []string `toml:"urls_v6"` + UrlsV6 []string `toml:urls_v6` // host ping function pingHost HostPinger @@ -71,11 +71,11 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { // Spin off a go routine for each url to ping for _, url := range p.Urls { wg.Add(1) - go p.pingToURL(url, false, &wg, acc) + go p.pingToURL(url, false, wg, acc) } for _, url := range p.UrlsV6 { wg.Add(1) - go p.pingToURL(url, true, &wg, acc) + go p.pingToURL(url, true, wg, acc) } wg.Wait() @@ -83,7 +83,7 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { return nil } -func (p *Ping) pingToURL(u string, isV6 bool, wg *sync.WaitGroup, acc telegraf.Accumulator) { +func (p *Ping) pingToURL(u string, isV6 bool, wg sync.WaitGroup, acc telegraf.Accumulator) { defer wg.Done() tags := map[string]string{"url": u} From d326e1fb2dd7b3759cc65f4e4ab09c036e7e7f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sat, 22 Sep 2018 00:48:49 +0900 Subject: [PATCH 11/26] Revert "edit README.md" This reverts commit 09bef984151b730ffb450a7399a4f03053240c33. --- plugins/inputs/ping/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/inputs/ping/README.md b/plugins/inputs/ping/README.md index a76e5723cdead..4996fdc37bf9f 100644 --- a/plugins/inputs/ping/README.md +++ b/plugins/inputs/ping/README.md @@ -15,9 +15,6 @@ apt-get install iputils-ping ## List of urls to ping urls = ["example.org"] - ## List of urls to ping to ipv6 address - urls_v6 = ["example.org"] - ## Number of pings to send per collection (ping -c ) # count = 1 From 2c5d0dfabc423271cd6ce0679f492fa7491c9ea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sat, 22 Sep 2018 00:48:54 +0900 Subject: [PATCH 12/26] Revert "add support ipv6 ping" This reverts commit 19461bad474899c8909593c7768d48b87c580f2a. --- plugins/inputs/ping/ping.go | 21 ++++++--------------- plugins/inputs/ping/ping_windows.go | 21 ++++++--------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index c4fd27dbe59cf..059bbf9e0a91d 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -22,7 +22,7 @@ import ( // 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) -type HostPinger func(timeout float64, isV6 bool, args ...string) (string, error) +type HostPinger func(timeout float64, args ...string) (string, error) type Ping struct { // Interval at which to ping (ping -i ) @@ -89,11 +89,7 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { // Spin off a go routine for each url to ping for _, url := range p.Urls { wg.Add(1) - go p.pingToURL(url, false, wg, acc) - } - for _, url := range p.UrlsV6 { - wg.Add(1) - go p.pingToURL(url, true, wg, acc) + p.pingToURL(url, wg, acc) } wg.wait() @@ -101,7 +97,7 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { return nil } -func (p *Ping) pingToURL(u string, isV6 bool, wg sync.WaitGroup, acc telegraf.Accumulator) { +func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) { defer wg.Done() tags := map[string]string{"url": u} fields := map[string]interface{}{"result_code": 0} @@ -117,7 +113,7 @@ func (p *Ping) pingToURL(u string, isV6 bool, wg sync.WaitGroup, acc telegraf.Ac args := p.args(u, runtime.GOOS) totalTimeout := float64(p.Count)*p.Timeout + float64(p.Count-1)*p.PingInterval - out, err := p.pingHost(totalTimeout, isV6, args...) + out, err := p.pingHost(totalTimeout, args...) if err != nil { // Some implementations of ping return a 1 exit code on // timeout, if this occurs we will not exit and try to parse @@ -171,13 +167,8 @@ func (p *Ping) pingToURL(u string, isV6 bool, wg sync.WaitGroup, acc telegraf.Ac acc.AddFields("ping", fields, tags) } -func hostPinger(timeout float64, isV6 bool, args ...string) (string, error) { - pingCmd := "ping" - if isV6 == true { - pingCmd = "ping6" - } - - bin, err := exec.lookpath(pingCmd) +func hostpinger(timeout float64, args ...string) (string, error) { + bin, err := exec.lookpath("ping") if err != nil { return "", err } diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index fcbe7192d6eeb..623d97bbbe358 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -21,7 +21,7 @@ import ( // 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) -type HostPinger func(timeout float64, isV6 bool, args ...string) (string, error) +type HostPinger func(timeout float64, args ...string) (string, error) type Ping struct { // Number of pings to send (ping -c ) @@ -71,11 +71,7 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { // Spin off a go routine for each url to ping for _, url := range p.Urls { wg.Add(1) - go p.pingToURL(url, false, wg, acc) - } - for _, url := range p.UrlsV6 { - wg.Add(1) - go p.pingToURL(url, true, wg, acc) + p.pingToURL(url, wg, acc) } wg.Wait() @@ -83,7 +79,7 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { return nil } -func (p *Ping) pingToURL(u string, isV6 bool, wg sync.WaitGroup, acc telegraf.Accumulator) { +func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) { defer wg.Done() tags := map[string]string{"url": u} @@ -99,7 +95,7 @@ func (p *Ping) pingToURL(u string, isV6 bool, wg sync.WaitGroup, acc telegraf.Ac args := p.args(u) totalTimeout := p.timeout() * float64(p.Count) - out, err := p.pingHost(totalTimeout, isV6, args...) + out, err := p.pingHost(totalTimeout, args...) // ping host return exitcode != 0 also when there was no response from host // but command was execute successfully var pendingError error @@ -142,13 +138,8 @@ func (p *Ping) pingToURL(u string, isV6 bool, wg sync.WaitGroup, acc telegraf.Ac acc.AddFields("ping", fields, tags) } -func hostPinger(timeout float64, isV6 bool, args ...string) (string, error) { - pingCmd := "ping" - if isV6 == true { - pingCmd = "ping6" - } - - bin, err := exec.LookPath(pingCmd) +func hostPinger(timeout float64, args ...string) (string, error) { + bin, err := exec.LookPath("ping") if err != nil { return "", err } From 7106e7bf2292057bdefd2066662d8dfadea589eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sat, 22 Sep 2018 00:53:34 +0900 Subject: [PATCH 13/26] revert previous ipv6 way --- plugins/inputs/ping/ping.go | 50 +++++++++++++---------------- plugins/inputs/ping/ping_windows.go | 6 ---- 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index 059bbf9e0a91d..82b799f6c6cd5 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -43,9 +43,6 @@ type Ping struct { // URLs to ping Urls []string - // URLs to ping ipv6 address - UrlsV6 []string `toml:urls_v6` - // host ping function pingHost HostPinger } @@ -58,9 +55,6 @@ const sampleConfig = ` ## List of urls to ping urls = ["example.org"] - ## List of urls to ping with ipv6 protocol - urls_v6 = ["example.org"] - ## Number of pings to send per collection (ping -c ) # count = 1 @@ -92,7 +86,7 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { p.pingToURL(url, wg, acc) } - wg.wait() + wg.Wait() return nil } @@ -167,55 +161,55 @@ func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) acc.AddFields("ping", fields, tags) } -func hostpinger(timeout float64, args ...string) (string, error) { - bin, err := exec.lookpath("ping") +func hostPinger(timeout float64, args ...string) (string, error) { + bin, err := exec.LookPath("ping") if err != nil { return "", err } - c := exec.command(bin, args...) - out, err := internal.combinedoutputtimeout(c, - time.second*time.duration(timeout+5)) + c := exec.Command(bin, args...) + out, err := internal.CombinedOutputTimeout(c, + time.Second*time.Duration(timeout+5)) return string(out), err } // args returns the arguments for the 'ping' executable -func (p *ping) args(url string, system string) []string { +func (p *Ping) args(url string, system string) []string { // build the ping command args based on toml config - args := []string{"-c", strconv.itoa(p.count), "-n", "-s", "16"} - if p.pinginterval > 0 { - args = append(args, "-i", strconv.formatfloat(p.pinginterval, 'f', -1, 64)) + args := []string{"-c", strconv.Itoa(p.Count), "-n", "-s", "16"} + if p.PingInterval > 0 { + args = append(args, "-i", strconv.FormatFloat(p.PingInterval, 'f', -1, 64)) } - if p.timeout > 0 { + if p.Timeout > 0 { switch system { case "darwin", "freebsd", "netbsd", "openbsd": - args = append(args, "-w", strconv.formatfloat(p.timeout*1000, 'f', -1, 64)) + args = append(args, "-w", strconv.FormatFloat(p.Timeout*1000, 'f', -1, 64)) case "linux": - args = append(args, "-w", strconv.formatfloat(p.timeout, 'f', -1, 64)) + args = append(args, "-w", strconv.FormatFloat(p.Timeout, 'f', -1, 64)) default: // not sure the best option here, just assume gnu ping? - args = append(args, "-w", strconv.formatfloat(p.timeout, 'f', -1, 64)) + args = append(args, "-w", strconv.FormatFloat(p.Timeout, 'f', -1, 64)) } } - if p.deadline > 0 { + if p.Deadline > 0 { switch system { case "darwin", "freebsd", "netbsd", "openbsd": - args = append(args, "-t", strconv.itoa(p.deadline)) + args = append(args, "-t", strconv.Itoa(p.Deadline)) case "linux": - args = append(args, "-w", strconv.itoa(p.deadline)) + args = append(args, "-w", strconv.Itoa(p.Deadline)) default: // not sure the best option here, just assume gnu ping? - args = append(args, "-w", strconv.itoa(p.deadline)) + args = append(args, "-w", strconv.Itoa(p.Deadline)) } } - if p.interface != "" { + if p.Interface != "" { switch system { case "darwin", "freebsd", "netbsd", "openbsd": - args = append(args, "-s", p.interface) + args = append(args, "-s", p.Interface) case "linux": - args = append(args, "-i", p.interface) + args = append(args, "-i", p.Interface) default: // not sure the best option here, just assume gnu ping? - args = append(args, "-i", p.interface) + args = append(args, "-i", p.Interface) } } args = append(args, url) diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index 623d97bbbe358..3ec0fcb724d19 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -33,9 +33,6 @@ type Ping struct { // URLs to ping Urls []string - // URLs to ping ipv6 address - UrlsV6 []string `toml:urls_v6` - // host ping function pingHost HostPinger } @@ -48,9 +45,6 @@ const sampleConfig = ` ## List of urls to ping urls = ["www.google.com"] - ## List of urls to ping with ipv6 protocol - urls_v6 = ["www.google.com"] - ## number of pings to send per collection (ping -n ) # count = 1 From 405cf175178faaec4735c5fd14106e229b7d27dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sat, 22 Sep 2018 01:08:00 +0900 Subject: [PATCH 14/26] use ping binary option --- plugins/inputs/ping/ping.go | 15 +++++++++++---- plugins/inputs/ping/ping_test.go | 10 +++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index 82b799f6c6cd5..0fbe6c9dd7cf9 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -22,7 +22,7 @@ import ( // 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) -type HostPinger func(timeout float64, args ...string) (string, error) +type HostPinger func(binary string, timeout float64, args ...string) (string, error) type Ping struct { // Interval at which to ping (ping -i ) @@ -43,6 +43,9 @@ type Ping struct { // URLs to ping Urls []string + // ping executable binary + Binary string + // host ping function pingHost HostPinger } @@ -71,6 +74,9 @@ const sampleConfig = ` ## Interface or source address to send ping from (ping -I ) ## on Darwin and Freebsd only source address possible: (ping -S ) # interface = "" + + ## Specify the ping executable binary, default is "ping" + # binary = "ping" ` func (_ *Ping) SampleConfig() string { @@ -107,7 +113,7 @@ func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) args := p.args(u, runtime.GOOS) totalTimeout := float64(p.Count)*p.Timeout + float64(p.Count-1)*p.PingInterval - out, err := p.pingHost(totalTimeout, args...) + out, err := p.pingHost(p.Binary, totalTimeout, args...) if err != nil { // Some implementations of ping return a 1 exit code on // timeout, if this occurs we will not exit and try to parse @@ -161,8 +167,8 @@ func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) acc.AddFields("ping", fields, tags) } -func hostPinger(timeout float64, args ...string) (string, error) { - bin, err := exec.LookPath("ping") +func hostPinger(binary string, timeout float64, args ...string) (string, error) { + bin, err := exec.LookPath(binary) if err != nil { return "", err } @@ -281,6 +287,7 @@ func init() { Count: 1, Timeout: 1.0, Deadline: 10, + Binary: "ping", } }) } diff --git a/plugins/inputs/ping/ping_test.go b/plugins/inputs/ping/ping_test.go index d5b82608aadd3..943889c5f2090 100644 --- a/plugins/inputs/ping/ping_test.go +++ b/plugins/inputs/ping/ping_test.go @@ -124,7 +124,7 @@ func TestArgs(t *testing.T) { } } -func mockHostPinger(timeout float64, args ...string) (string, error) { +func mockHostPinger(binary string, timeout float64, args ...string) (string, error) { return linuxPingOutput, nil } @@ -165,7 +165,7 @@ PING www.google.com (216.58.218.164) 56(84) bytes of data. rtt min/avg/max/mdev = 35.225/44.033/51.806/5.325 ms ` -func mockLossyHostPinger(timeout float64, args ...string) (string, error) { +func mockLossyHostPinger(binary string, timeout float64, args ...string) (string, error) { return lossyPingOutput, nil } @@ -200,7 +200,7 @@ Request timeout for icmp_seq 0 2 packets transmitted, 0 packets received, 100.0% packet loss ` -func mockErrorHostPinger(timeout float64, args ...string) (string, error) { +func mockErrorHostPinger(binary string, timeout float64, args ...string) (string, error) { // This error will not trigger correct error paths return errorPingOutput, nil } @@ -225,7 +225,7 @@ func TestBadPingGather(t *testing.T) { acc.AssertContainsTaggedFields(t, "ping", fields, tags) } -func mockFatalHostPinger(timeout float64, args ...string) (string, error) { +func mockFatalHostPinger(binary string, timeout float64, args ...string) (string, error) { return fatalPingOutput, errors.New("So very bad") } @@ -265,7 +265,7 @@ func TestErrorWithHostNamePingGather(t *testing.T) { var acc testutil.Accumulator p := Ping{ Urls: []string{"www.amazon.com"}, - pingHost: func(timeout float64, args ...string) (string, error) { + pingHost: func(binary string, timeout float64, args ...string) (string, error) { return param.out, errors.New("So very bad") }, } From 87be1c8c971fa631fafb9c3452cbc7bab0aac3e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sat, 22 Sep 2018 01:10:22 +0900 Subject: [PATCH 15/26] use ping binary option for windows --- plugins/inputs/ping/ping_windows.go | 14 ++++++++++---- plugins/inputs/ping/ping_windows_test.go | 12 ++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index 3ec0fcb724d19..6b09fae1968ad 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -21,7 +21,7 @@ import ( // 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) -type HostPinger func(timeout float64, args ...string) (string, error) +type HostPinger func(binary string, timeout float64, args ...string) (string, error) type Ping struct { // Number of pings to send (ping -c ) @@ -33,6 +33,9 @@ type Ping struct { // URLs to ping Urls []string + // ping executable binary + Binary string + // host ping function pingHost HostPinger } @@ -50,6 +53,9 @@ const sampleConfig = ` ## Ping timeout, in seconds. 0.0 means default timeout (ping -w ) # timeout = 0.0 + + ## Specify the ping executable binary, default is "ping" + # binary = "ping" ` func (s *Ping) SampleConfig() string { @@ -89,7 +95,7 @@ func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) args := p.args(u) totalTimeout := p.timeout() * float64(p.Count) - out, err := p.pingHost(totalTimeout, args...) + out, err := p.pingHost(p.Binary, totalTimeout, args...) // ping host return exitcode != 0 also when there was no response from host // but command was execute successfully var pendingError error @@ -132,8 +138,8 @@ func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) acc.AddFields("ping", fields, tags) } -func hostPinger(timeout float64, args ...string) (string, error) { - bin, err := exec.LookPath("ping") +func hostPinger(binary string, timeout float64, args ...string) (string, error) { + bin, err := exec.LookPath(binary) if err != nil { return "", err } diff --git a/plugins/inputs/ping/ping_windows_test.go b/plugins/inputs/ping/ping_windows_test.go index 178e42fcb56dd..d36541fd9c399 100644 --- a/plugins/inputs/ping/ping_windows_test.go +++ b/plugins/inputs/ping/ping_windows_test.go @@ -59,7 +59,7 @@ func TestHost(t *testing.T) { assert.Equal(t, 52, max, "Max 52") } -func mockHostPinger(timeout float64, args ...string) (string, error) { +func mockHostPinger(binary string, timeout float64, args ...string) (string, error) { return winENPingOutput, nil } @@ -102,7 +102,7 @@ Statystyka badania ping dla 195.187.242.157: (100% straty), ` -func mockErrorHostPinger(timeout float64, args ...string) (string, error) { +func mockErrorHostPinger(binary string, timeout float64, args ...string) (string, error) { return errorPingOutput, errors.New("No packets received") } @@ -147,7 +147,7 @@ Szacunkowy czas błądzenia pakietów w millisekundach: Minimum = 114 ms, Maksimum = 119 ms, Czas średni = 115 ms ` -func mockLossyHostPinger(timeout float64, args ...string) (string, error) { +func mockLossyHostPinger(binary string, timeout float64, args ...string) (string, error) { return lossyPingOutput, nil } @@ -207,7 +207,7 @@ Options: ` -func mockFatalHostPinger(timeout float64, args ...string) (string, error) { +func mockFatalHostPinger(binary string, timeout float64, args ...string) (string, error) { return fatalPingOutput, errors.New("So very bad") } @@ -249,7 +249,7 @@ Ping statistics for 8.8.8.8: Packets: Sent = 4, Received = 1, Lost = 3 (75% loss), ` -func mockUnreachableHostPinger(timeout float64, args ...string) (string, error) { +func mockUnreachableHostPinger(binary string, timeout float64, args ...string) (string, error) { return UnreachablePingOutput, errors.New("So very bad") } @@ -298,7 +298,7 @@ Ping statistics for 8.8.8.8: Packets: Sent = 4, Received = 1, Lost = 3 (75% loss), ` -func mockTTLExpiredPinger(timeout float64, args ...string) (string, error) { +func mockTTLExpiredPinger(binary string, timeout float64, args ...string) (string, error) { return TTLExpiredPingOutput, errors.New("So very bad") } From 2f6dfdf0425a946529f40366b6ef80002bc26297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sat, 22 Sep 2018 01:20:35 +0900 Subject: [PATCH 16/26] use arguments options --- plugins/inputs/ping/ping.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index 0fbe6c9dd7cf9..9ffa083348c44 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -43,9 +43,13 @@ type Ping struct { // URLs to ping Urls []string - // ping executable binary + // Ping executable binary Binary string + // Arguments for ping command. + // when `Arguments` is not empty, other options (ping_interval, timeout, etc) will be ignored + Arguments []string + // host ping function pingHost HostPinger } @@ -77,6 +81,10 @@ const sampleConfig = ` ## Specify the ping executable binary, default is "ping" # binary = "ping" + + ## Arguments for ping command + ## when arguments is not empty, other options (ping_interval, timeout, etc) will be ignored + # arguments = ["-c", "3"] ` func (_ *Ping) SampleConfig() string { @@ -180,6 +188,10 @@ func hostPinger(binary string, timeout float64, args ...string) (string, error) // args returns the arguments for the 'ping' executable func (p *Ping) args(url string, system string) []string { + if len(p.Arguments) > 0 { + return p.Arguments + } + // build the ping command args based on toml config args := []string{"-c", strconv.Itoa(p.Count), "-n", "-s", "16"} if p.PingInterval > 0 { @@ -288,6 +300,7 @@ func init() { Timeout: 1.0, Deadline: 10, Binary: "ping", + Arguments: []string{}, } }) } From 03f2c93db7ab23ae65b78ffede9f8376f7bdf07d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sat, 22 Sep 2018 01:23:41 +0900 Subject: [PATCH 17/26] use arguments options for windows --- plugins/inputs/ping/ping_windows.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index 6b09fae1968ad..ad04f74693141 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -33,9 +33,13 @@ type Ping struct { // URLs to ping Urls []string - // ping executable binary + // Ping executable binary Binary string + // Arguments for ping command. + // when `Arguments` is not empty, other options (ping_interval, timeout, etc) will be ignored + Arguments []string + // host ping function pingHost HostPinger } @@ -56,6 +60,10 @@ const sampleConfig = ` ## Specify the ping executable binary, default is "ping" # binary = "ping" + + ## Arguments for ping command + ## when arguments is not empty, other options (ping_interval, timeout, etc) will be ignored + # arguemnts = ["-c", "3"] ` func (s *Ping) SampleConfig() string { @@ -151,6 +159,10 @@ func hostPinger(binary string, timeout float64, args ...string) (string, error) // args returns the arguments for the 'ping' executable func (p *Ping) args(url string) []string { + if len(p.Arguments) > 0 { + return p.Arguments + } + args := []string{"-n", strconv.Itoa(p.Count)} if p.Timeout > 0 { @@ -233,8 +245,10 @@ func (p *Ping) timeout() float64 { func init() { inputs.Add("ping", func() telegraf.Input { return &Ping{ - pingHost: hostPinger, - Count: 1, + pingHost: hostPinger, + Count: 1, + Binary: "ping", + Arguments: []string{}, } }) } From 4665d5acb23b85d0270399a3612d73bac1bc018e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sat, 22 Sep 2018 01:28:34 +0900 Subject: [PATCH 18/26] default timeout there is no way to get totalTimeout if arguments option used --- plugins/inputs/ping/ping.go | 5 ++++- plugins/inputs/ping/ping_windows.go | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index 9ffa083348c44..9eb046289fbd1 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -119,7 +119,10 @@ func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) } args := p.args(u, runtime.GOOS) - totalTimeout := float64(p.Count)*p.Timeout + float64(p.Count-1)*p.PingInterval + totalTimeout := 60.0 + if len(p.Arguments) == 0 { + totalTimeout = float64(p.Count)*p.Timeout + float64(p.Count-1)*p.PingInterval + } out, err := p.pingHost(p.Binary, totalTimeout, args...) if err != nil { diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index ad04f74693141..edc2ca34c0005 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -102,7 +102,11 @@ func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) } args := p.args(u) - totalTimeout := p.timeout() * float64(p.Count) + totalTimeout := 60.0 + if len(p.Arguments) == 0 { + totalTimeout = p.timeout() * float64(p.Count) + } + out, err := p.pingHost(p.Binary, totalTimeout, args...) // ping host return exitcode != 0 also when there was no response from host // but command was execute successfully From 65c9e8608d775fd08dfe7c06da4a3d989f2fe198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sat, 22 Sep 2018 01:54:00 +0900 Subject: [PATCH 19/26] fix invalid ping options for each operation systems --- plugins/inputs/ping/ping.go | 14 +++++++++----- plugins/inputs/ping/ping_test.go | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index 9eb046289fbd1..9131e56ac4a8f 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -202,13 +202,15 @@ func (p *Ping) args(url string, system string) []string { } if p.Timeout > 0 { switch system { - case "darwin", "freebsd", "netbsd", "openbsd": + case "darwin": + args = append(args, "-W", strconv.FormatFloat(p.Timeout*1000, 'f', -1, 64)) + case "freebsd", "netbsd", "openbsd": args = append(args, "-w", strconv.FormatFloat(p.Timeout*1000, 'f', -1, 64)) case "linux": - args = append(args, "-w", strconv.FormatFloat(p.Timeout, 'f', -1, 64)) + args = append(args, "-W", strconv.FormatFloat(p.Timeout, 'f', -1, 64)) default: // not sure the best option here, just assume gnu ping? - args = append(args, "-w", strconv.FormatFloat(p.Timeout, 'f', -1, 64)) + args = append(args, "-W", strconv.FormatFloat(p.Timeout, 'f', -1, 64)) } } if p.Deadline > 0 { @@ -224,10 +226,12 @@ func (p *Ping) args(url string, system string) []string { } if p.Interface != "" { switch system { - case "darwin", "freebsd", "netbsd", "openbsd": + case "darwin": + args = append(args, "-I", p.Interface) + case "freebsd", "netbsd", "openbsd": args = append(args, "-s", p.Interface) case "linux": - args = append(args, "-i", p.Interface) + args = append(args, "-I", p.Interface) default: // not sure the best option here, just assume gnu ping? args = append(args, "-i", p.Interface) diff --git a/plugins/inputs/ping/ping_test.go b/plugins/inputs/ping/ping_test.go index 943889c5f2090..1904b849553d8 100644 --- a/plugins/inputs/ping/ping_test.go +++ b/plugins/inputs/ping/ping_test.go @@ -110,9 +110,9 @@ func TestArgs(t *testing.T) { system string output []string }{ - {"darwin", []string{"-c", "2", "-n", "-s", "16", "-i", "1.2", "-W", "12000", "-t", "24", "-S", "eth0", "www.google.com"}}, + {"darwin", []string{"-c", "2", "-n", "-s", "16", "-i", "1.2", "-W", "12000", "-t", "24", "-I", "eth0", "www.google.com"}}, {"linux", []string{"-c", "2", "-n", "-s", "16", "-i", "1.2", "-W", "12", "-w", "24", "-I", "eth0", "www.google.com"}}, - {"anything else", []string{"-c", "2", "-n", "-s", "16", "-i", "1.2", "-W", "12", "-w", "24", "-I", "eth0", "www.google.com"}}, + {"anything else", []string{"-c", "2", "-n", "-s", "16", "-i", "1.2", "-W", "12", "-w", "24", "-i", "eth0", "www.google.com"}}, } for i := range systemCases { actual := p.args("www.google.com", systemCases[i].system) From 8269638729671b7bd6afc74ca349ccf4315d4e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Wed, 26 Sep 2018 00:45:05 +0900 Subject: [PATCH 20/26] not to copy lock value (sync.WaitGroup) --- plugins/inputs/ping/ping.go | 14 +++++++------- plugins/inputs/ping/ping_windows.go | 13 +++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index 9131e56ac4a8f..0ec35f73ffdc1 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -25,6 +25,8 @@ import ( type HostPinger func(binary string, timeout float64, args ...string) (string, error) type Ping struct { + wg sync.WaitGroup + // Interval at which to ping (ping -i ) PingInterval float64 `toml:"ping_interval"` @@ -92,21 +94,19 @@ func (_ *Ping) SampleConfig() string { } func (p *Ping) Gather(acc telegraf.Accumulator) error { - var wg sync.WaitGroup - // Spin off a go routine for each url to ping for _, url := range p.Urls { - wg.Add(1) - p.pingToURL(url, wg, acc) + p.wg.Add(1) + p.pingToURL(url, acc) } - wg.Wait() + p.wg.Wait() return nil } -func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) { - defer wg.Done() +func (p *Ping) pingToURL(u string, acc telegraf.Accumulator) { + defer p.wg.Done() tags := map[string]string{"url": u} fields := map[string]interface{}{"result_code": 0} diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index edc2ca34c0005..7e93e5e6b6339 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -24,6 +24,8 @@ import ( type HostPinger func(binary string, timeout float64, args ...string) (string, error) type Ping struct { + wg sync.WaitGroup + // Number of pings to send (ping -c ) Count int @@ -74,21 +76,20 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { if p.Count < 1 { p.Count = 1 } - var wg sync.WaitGroup // Spin off a go routine for each url to ping for _, url := range p.Urls { - wg.Add(1) - p.pingToURL(url, wg, acc) + p.wg.Add(1) + p.pingToURL(url, acc) } - wg.Wait() + p.wg.Wait() return nil } -func (p *Ping) pingToURL(u string, wg sync.WaitGroup, acc telegraf.Accumulator) { - defer wg.Done() +func (p *Ping) pingToURL(u string, acc telegraf.Accumulator) { + defer p.wg.Done() tags := map[string]string{"url": u} fields := map[string]interface{}{"result_code": 0} From e15adbbfaf8dffde392a885c65bfea10b1ba4b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Wed, 26 Sep 2018 21:13:22 +0900 Subject: [PATCH 21/26] add appropriatte unit test --- plugins/inputs/ping/ping_test.go | 30 ++++++++++++++++++++++ plugins/inputs/ping/ping_windows_test.go | 32 ++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/plugins/inputs/ping/ping_test.go b/plugins/inputs/ping/ping_test.go index 1904b849553d8..867220b208486 100644 --- a/plugins/inputs/ping/ping_test.go +++ b/plugins/inputs/ping/ping_test.go @@ -124,6 +124,23 @@ func TestArgs(t *testing.T) { } } +func TestArguments(t *testing.T) { + arguments := []string{"-c", "3"} + p := Ping{ + Count: 2, + Interface: "eth0", + Timeout: 12.0, + Deadline: 24, + PingInterval: 1.2, + Arguments: arguments, + } + + for _, system := range []string{"darwin", "linux", "anything else"} { + actual := p.args("www.google.com", system) + require.True(t, reflect.DeepEqual(actual, arguments), "Expected: %s Actual: %s", arguments, actual) + } +} + func mockHostPinger(binary string, timeout float64, args ...string) (string, error) { return linuxPingOutput, nil } @@ -274,3 +291,16 @@ func TestErrorWithHostNamePingGather(t *testing.T) { assert.Contains(t, acc.Errors, param.error) } } + +func TestPingBinary(t *testing.T) { + var acc testutil.Accumulator + p := Ping{ + Urls: []string{"www.google.com"}, + Binary: "ping6", + pingHost: func(binary string, timeout float64, args ...string) (string, error) { + assert.True(t, binary == "ping6") + return "", nil + }, + } + acc.GatherError(p.Gather) +} diff --git a/plugins/inputs/ping/ping_windows_test.go b/plugins/inputs/ping/ping_windows_test.go index d36541fd9c399..cb0bff701523f 100644 --- a/plugins/inputs/ping/ping_windows_test.go +++ b/plugins/inputs/ping/ping_windows_test.go @@ -4,10 +4,12 @@ package ping import ( "errors" + "reflect" "testing" "github.com/influxdata/telegraf/testutil" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) // Windows ping format ( should support multilanguage ?) @@ -128,6 +130,23 @@ func TestBadPingGather(t *testing.T) { acc.AssertContainsTaggedFields(t, "ping", fields, tags) } +func TestArguments(t *testing.T) { + arguments := []string{"-c", "3"} + p := Ping{ + Count: 2, + Interface: "eth0", + Timeout: 12.0, + Deadline: 24, + PingInterval: 1.2, + Arguments: arguemnts, + } + + for _, system := range []string{"darwin", "linux", "anything else"} { + actual := p.args("www.google.com", system) + require.True(t, reflect.DeepEqual(actual, arguments), "Expected : %s Actual: %s", arguments, actual) + } +} + var lossyPingOutput = ` Badanie thecodinglove.com [66.6.44.4] z 9800 bajtami danych: Upłynął limit czasu żądania. @@ -333,3 +352,16 @@ func TestTTLExpiredPingGather(t *testing.T) { assert.False(t, acc.HasInt64Field("ping", "minimum_response_ms"), "Fatal ping should not have packet measurements") } + +func TestPingBinary(t *testing.T) { + var acc testutil.Accumulator + p := Ping{ + Urls: []string{"www.google.com"}, + Binary: "ping6", + pingHost: func(binary string, timeout float64, args ...string) (string, error) { + assert.True(t, binary == "ping6") + return "", nil + }, + } + acc.GatherError(p.Gather) +} From 3055b72207b494f860f0c239ba5ee98dac81444f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Wed, 26 Sep 2018 21:22:12 +0900 Subject: [PATCH 22/26] fix unit test --- plugins/inputs/ping/ping_windows_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/inputs/ping/ping_windows_test.go b/plugins/inputs/ping/ping_windows_test.go index cb0bff701523f..f66d5ea0692f6 100644 --- a/plugins/inputs/ping/ping_windows_test.go +++ b/plugins/inputs/ping/ping_windows_test.go @@ -141,10 +141,8 @@ func TestArguments(t *testing.T) { Arguments: arguemnts, } - for _, system := range []string{"darwin", "linux", "anything else"} { - actual := p.args("www.google.com", system) - require.True(t, reflect.DeepEqual(actual, arguments), "Expected : %s Actual: %s", arguments, actual) - } + actual := p.args("www.google.com") + require.True(t, reflect.DeepEqual(actual, arguments), "Expected : %s Actual: %s", arguments, actual) } var lossyPingOutput = ` From 64321eace99e2105236182d8bd5be4048a257ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Wed, 26 Sep 2018 22:50:56 +0900 Subject: [PATCH 23/26] fix unit test --- plugins/inputs/ping/ping_windows_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugins/inputs/ping/ping_windows_test.go b/plugins/inputs/ping/ping_windows_test.go index f66d5ea0692f6..47b5b48c796f2 100644 --- a/plugins/inputs/ping/ping_windows_test.go +++ b/plugins/inputs/ping/ping_windows_test.go @@ -133,12 +133,9 @@ func TestBadPingGather(t *testing.T) { func TestArguments(t *testing.T) { arguments := []string{"-c", "3"} p := Ping{ - Count: 2, - Interface: "eth0", - Timeout: 12.0, - Deadline: 24, - PingInterval: 1.2, - Arguments: arguemnts, + Count: 2, + Timeout: 12.0, + Arguments: arguemnts, } actual := p.args("www.google.com") From a76e20ed4c3602933946126b0608b51f543142f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Wed, 26 Sep 2018 23:31:09 +0900 Subject: [PATCH 24/26] fix typing err --- plugins/inputs/ping/ping_windows_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inputs/ping/ping_windows_test.go b/plugins/inputs/ping/ping_windows_test.go index 47b5b48c796f2..4618ec4db4942 100644 --- a/plugins/inputs/ping/ping_windows_test.go +++ b/plugins/inputs/ping/ping_windows_test.go @@ -135,7 +135,7 @@ func TestArguments(t *testing.T) { p := Ping{ Count: 2, Timeout: 12.0, - Arguments: arguemnts, + Arguments: arguments, } actual := p.args("www.google.com") From ff00b22d9014833cb9bb9d9b566a42e61b897e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Thu, 27 Sep 2018 12:36:29 +0900 Subject: [PATCH 25/26] fix typing error --- plugins/inputs/ping/ping_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index 7e93e5e6b6339..cd06c3f39dad3 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -65,7 +65,7 @@ const sampleConfig = ` ## Arguments for ping command ## when arguments is not empty, other options (ping_interval, timeout, etc) will be ignored - # arguemnts = ["-c", "3"] + # arguments = ["-c", "3"] ` func (s *Ping) SampleConfig() string { From 71169ba4b7724a9fc6057866dfd48b351706b396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8C=E1=85=A2=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC?= Date: Sat, 29 Sep 2018 18:18:01 +0900 Subject: [PATCH 26/26] little fix --- plugins/inputs/ping/ping.go | 6 +++--- plugins/inputs/ping/ping_windows.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index 0ec35f73ffdc1..a95f27ebf224a 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -97,7 +97,7 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { // Spin off a go routine for each url to ping for _, url := range p.Urls { p.wg.Add(1) - p.pingToURL(url, acc) + go p.pingToURL(url, acc) } p.wg.Wait() @@ -209,7 +209,7 @@ func (p *Ping) args(url string, system string) []string { case "linux": args = append(args, "-W", strconv.FormatFloat(p.Timeout, 'f', -1, 64)) default: - // not sure the best option here, just assume gnu ping? + // Not sure the best option here, just assume GNU ping? args = append(args, "-W", strconv.FormatFloat(p.Timeout, 'f', -1, 64)) } } @@ -241,7 +241,7 @@ func (p *Ping) args(url string, system string) []string { return args } -// processpingoutput takes in a string output from the ping command, like: +// processPingOutput takes in a string output from the ping command, like: // // ping www.google.com (173.194.115.84): 56 data bytes // 64 bytes from 173.194.115.84: icmp_seq=0 ttl=54 time=52.172 ms diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index cd06c3f39dad3..6064fabe4b6dc 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -80,7 +80,7 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { // Spin off a go routine for each url to ping for _, url := range p.Urls { p.wg.Add(1) - p.pingToURL(url, acc) + go p.pingToURL(url, acc) } p.wg.Wait()