Remove log message on ping timeout (#3126)

This commit is contained in:
Daniel Nelson 2017-08-16 11:59:41 -07:00 committed by GitHub
parent 0d6aca44fc
commit 733dcf6c65
2 changed files with 27 additions and 5 deletions

View File

@ -4,11 +4,13 @@ package ping
import ( import (
"errors" "errors"
"fmt"
"os/exec" "os/exec"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"syscall"
"time" "time"
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
@ -76,17 +78,36 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error {
defer wg.Done() defer wg.Done()
args := p.args(u) args := p.args(u)
totalTimeout := float64(p.Count)*p.Timeout + float64(p.Count-1)*p.PingInterval totalTimeout := float64(p.Count)*p.Timeout + float64(p.Count-1)*p.PingInterval
out, err := p.pingHost(totalTimeout, args...) out, err := p.pingHost(totalTimeout, args...)
if err != nil { if err != nil {
// Combine go err + stderr output // Some implementations of ping return a 1 exit code on
acc.AddError(errors.New( // timeout, if this occurs we will not exit and try to parse
strings.TrimSpace(out) + ", " + err.Error())) // the output.
status := -1
if exitError, ok := err.(*exec.ExitError); ok {
if ws, ok := exitError.Sys().(syscall.WaitStatus); ok {
status = ws.ExitStatus()
}
}
if status != 1 {
// Combine go err + stderr output
out = strings.TrimSpace(out)
if len(out) > 0 {
acc.AddError(fmt.Errorf("%s, %s", out, err))
} else {
acc.AddError(err)
}
return
}
} }
tags := map[string]string{"url": u} tags := map[string]string{"url": u}
trans, rec, min, avg, max, stddev, err := processPingOutput(out) trans, rec, min, avg, max, stddev, err := processPingOutput(out)
if err != nil { if err != nil {
// fatal error // fatal error
acc.AddError(err) acc.AddError(fmt.Errorf("%s: %s", err, u))
return return
} }
// Calculate packet loss percentage // Calculate packet loss percentage

View File

@ -211,7 +211,8 @@ Request timeout for icmp_seq 0
` `
func mockErrorHostPinger(timeout float64, args ...string) (string, error) { func mockErrorHostPinger(timeout float64, args ...string) (string, error) {
return errorPingOutput, errors.New("No packets received") // This error will not trigger correct error paths
return errorPingOutput, nil
} }
// Test that Gather works on a ping with no transmitted packets, even though the // Test that Gather works on a ping with no transmitted packets, even though the