Skip to content

Commit f5ea13a

Browse files
efficksdanielnelson
authored andcommitted
Fix ping plugin not reporting zero durations (#3778)
1 parent 32dd1b3 commit f5ea13a

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

plugins/inputs/ping/ping.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,16 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error {
129129
fields["packets_transmitted"] = trans
130130
fields["packets_received"] = rec
131131
fields["percent_packet_loss"] = loss
132-
if min > 0 {
132+
if min >= 0 {
133133
fields["minimum_response_ms"] = min
134134
}
135-
if avg > 0 {
135+
if avg >= 0 {
136136
fields["average_response_ms"] = avg
137137
}
138-
if max > 0 {
138+
if max >= 0 {
139139
fields["maximum_response_ms"] = max
140140
}
141-
if stddev > 0 {
141+
if stddev >= 0 {
142142
fields["standard_deviation_ms"] = stddev
143143
}
144144
acc.AddFields("ping", fields, tags)
@@ -207,7 +207,7 @@ func (p *Ping) args(url string) []string {
207207
// It returns (<transmitted packets>, <received packets>, <average response>)
208208
func processPingOutput(out string) (int, int, float64, float64, float64, float64, error) {
209209
var trans, recv int
210-
var min, avg, max, stddev float64
210+
var min, avg, max, stddev float64 = -1.0, -1.0, -1.0, -1.0
211211
// Set this error to nil if we find a 'transmitted' line
212212
err := errors.New("Fatal error processing ping output")
213213
lines := strings.Split(out, "\n")

plugins/inputs/ping/ping_windows.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,32 +93,32 @@ func processPingOutput(out string) (int, int, int, int, int, int, error) {
9393

9494
// stats data should contain 4 members: entireExpression + ( Send, Receive, Lost )
9595
if len(stats) != 4 {
96-
return 0, 0, 0, 0, 0, 0, err
96+
return 0, 0, 0, -1, -1, -1, err
9797
}
9898
trans, err := strconv.Atoi(stats[1])
9999
if err != nil {
100-
return 0, 0, 0, 0, 0, 0, err
100+
return 0, 0, 0, -1, -1, -1, err
101101
}
102102
receivedPacket, err := strconv.Atoi(stats[2])
103103
if err != nil {
104-
return 0, 0, 0, 0, 0, 0, err
104+
return 0, 0, 0, -1, -1, -1, err
105105
}
106106

107107
// aproxs data should contain 4 members: entireExpression + ( min, max, avg )
108108
if len(aproxs) != 4 {
109-
return trans, receivedReply, receivedPacket, 0, 0, 0, err
109+
return trans, receivedReply, receivedPacket, -1, -1, -1, err
110110
}
111111
min, err := strconv.Atoi(aproxs[1])
112112
if err != nil {
113-
return trans, receivedReply, receivedPacket, 0, 0, 0, err
113+
return trans, receivedReply, receivedPacket, -1, -1, -1, err
114114
}
115115
max, err := strconv.Atoi(aproxs[2])
116116
if err != nil {
117-
return trans, receivedReply, receivedPacket, 0, 0, 0, err
117+
return trans, receivedReply, receivedPacket, -1, -1, -1, err
118118
}
119119
avg, err := strconv.Atoi(aproxs[3])
120120
if err != nil {
121-
return 0, 0, 0, 0, 0, 0, err
121+
return 0, 0, 0, -1, -1, -1, err
122122
}
123123

124124
return trans, receivedReply, receivedPacket, avg, min, max, err
@@ -201,13 +201,13 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error {
201201
fields["packets_received"] = receivePacket
202202
fields["percent_packet_loss"] = lossPackets
203203
fields["percent_reply_loss"] = lossReply
204-
if avg > 0 {
204+
if avg >= 0 {
205205
fields["average_response_ms"] = float64(avg)
206206
}
207-
if min > 0 {
207+
if min >= 0 {
208208
fields["minimum_response_ms"] = float64(min)
209209
}
210-
if max > 0 {
210+
if max >= 0 {
211211
fields["maximum_response_ms"] = float64(max)
212212
}
213213
acc.AddFields("ping", fields, tags)

0 commit comments

Comments
 (0)