Skip to content

Commit

Permalink
Fix ping plugin not reporting zero durations (#3778)
Browse files Browse the repository at this point in the history
  • Loading branch information
efficks authored and danielnelson committed Feb 9, 2018
1 parent 32dd1b3 commit f5ea13a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions plugins/inputs/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,16 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error {
fields["packets_transmitted"] = trans
fields["packets_received"] = rec
fields["percent_packet_loss"] = loss
if min > 0 {
if min >= 0 {
fields["minimum_response_ms"] = min
}
if avg > 0 {
if avg >= 0 {
fields["average_response_ms"] = avg
}
if max > 0 {
if max >= 0 {
fields["maximum_response_ms"] = max
}
if stddev > 0 {
if stddev >= 0 {
fields["standard_deviation_ms"] = stddev
}
acc.AddFields("ping", fields, tags)
Expand Down Expand Up @@ -207,7 +207,7 @@ func (p *Ping) args(url string) []string {
// It returns (<transmitted packets>, <received packets>, <average response>)
func processPingOutput(out string) (int, int, float64, float64, float64, float64, error) {
var trans, recv int
var min, avg, max, stddev float64
var min, avg, max, stddev float64 = -1.0, -1.0, -1.0, -1.0
// Set this error to nil if we find a 'transmitted' line
err := errors.New("Fatal error processing ping output")
lines := strings.Split(out, "\n")
Expand Down
20 changes: 10 additions & 10 deletions plugins/inputs/ping/ping_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,32 +93,32 @@ func processPingOutput(out string) (int, int, int, int, int, int, error) {

// stats data should contain 4 members: entireExpression + ( Send, Receive, Lost )
if len(stats) != 4 {
return 0, 0, 0, 0, 0, 0, err
return 0, 0, 0, -1, -1, -1, err
}
trans, err := strconv.Atoi(stats[1])
if err != nil {
return 0, 0, 0, 0, 0, 0, err
return 0, 0, 0, -1, -1, -1, err
}
receivedPacket, err := strconv.Atoi(stats[2])
if err != nil {
return 0, 0, 0, 0, 0, 0, err
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, 0, 0, 0, err
return trans, receivedReply, receivedPacket, -1, -1, -1, err
}
min, err := strconv.Atoi(aproxs[1])
if err != nil {
return trans, receivedReply, receivedPacket, 0, 0, 0, err
return trans, receivedReply, receivedPacket, -1, -1, -1, err
}
max, err := strconv.Atoi(aproxs[2])
if err != nil {
return trans, receivedReply, receivedPacket, 0, 0, 0, err
return trans, receivedReply, receivedPacket, -1, -1, -1, err
}
avg, err := strconv.Atoi(aproxs[3])
if err != nil {
return 0, 0, 0, 0, 0, 0, err
return 0, 0, 0, -1, -1, -1, err
}

return trans, receivedReply, receivedPacket, avg, min, max, err
Expand Down Expand Up @@ -201,13 +201,13 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error {
fields["packets_received"] = receivePacket
fields["percent_packet_loss"] = lossPackets
fields["percent_reply_loss"] = lossReply
if avg > 0 {
if avg >= 0 {
fields["average_response_ms"] = float64(avg)
}
if min > 0 {
if min >= 0 {
fields["minimum_response_ms"] = float64(min)
}
if max > 0 {
if max >= 0 {
fields["maximum_response_ms"] = float64(max)
}
acc.AddFields("ping", fields, tags)
Expand Down

0 comments on commit f5ea13a

Please sign in to comment.