From 64dd7b9649a0296475e6aab49baac275e46417ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=96=E5=A5=B3=E5=AD=A9=E7=9A=84=E5=B0=8F=E7=81=AB?= =?UTF-8?q?=E6=9F=B4?= <44471469+Erope@users.noreply.github.com> Date: Wed, 1 Mar 2023 22:06:44 +0800 Subject: [PATCH] Fix icmp ping --- cmd/agent/main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/agent/main.go b/cmd/agent/main.go index a8ee913..5fa90c2 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -337,8 +337,12 @@ func handleIcmpPingTask(task *pb.Task, result *pb.TaskResult) { err = pinger.Run() // Blocks until finished. } if err == nil { - result.Delay = float32(pinger.Statistics().AvgRtt.Microseconds()) / 1000.0 - result.Successful = true + if pinger.Statistics().PacketsRecv == 0 { + result.Data = "Ping 未收到回包" + } else { + result.Delay = float32(pinger.Statistics().AvgRtt.Microseconds()) / 1000.0 + result.Successful = true + } } else { result.Data = err.Error() }