add more logging to ping plugin

This commit is contained in:
Steven Soroka 2021-03-10 12:11:19 -05:00
parent 06e97756c8
commit 7651651867
1 changed files with 3 additions and 0 deletions

View File

@ -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 {
@ -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)