Skip to content

Commit

Permalink
add more logging to ping plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ssoroka committed Mar 10, 2021
1 parent 06e9775 commit 7651651
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/inputs/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func (p *Ping) pingToURLNative(destination string, acc telegraf.Accumulator) {

stats, err := p.nativePingFunc(destination)
if err != nil {
p.Log.Errorf("ping failed: %s", err.Error())
if strings.Contains(err.Error(), "unknown") {
fields["result_code"] = 1
} else {
Expand All @@ -224,12 +225,14 @@ func (p *Ping) pingToURLNative(destination string, acc telegraf.Accumulator) {
}

if stats.PacketsSent == 0 {
p.Log.Debug("no packets sent")
fields["result_code"] = 2
acc.AddFields("ping", fields, tags)
return
}

if stats.PacketsRecv == 0 {
p.Log.Debug("no packets received")
fields["result_code"] = 1
fields["percent_packet_loss"] = float64(100)
acc.AddFields("ping", fields, tags)
Expand Down

0 comments on commit 7651651

Please sign in to comment.