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 1/3] 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() } From 5c9341e57e24dec04120cf5fd4e5d15e6250916f 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 23:29:56 +0800 Subject: [PATCH 2/3] use goreleaser-cross:v1.19.2 see https://github.com/actions/checkout/issues/1169 --- .github/workflows/agent.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/agent.yml b/.github/workflows/agent.yml index fa9c1c6..09e1904 100644 --- a/.github/workflows/agent.yml +++ b/.github/workflows/agent.yml @@ -9,7 +9,7 @@ jobs: deploy: runs-on: ubuntu-latest container: - image: goreleaser/goreleaser-cross + image: goreleaser/goreleaser-cross:v1.19.2 steps: - uses: actions/checkout@master with: From 88328344e9641a1a9fc6c664e21edf6b54e214e5 Mon Sep 17 00:00:00 2001 From: naiba Date: Wed, 1 Mar 2023 23:42:39 +0800 Subject: [PATCH 3/3] refine --- cmd/agent/main.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/agent/main.go b/cmd/agent/main.go index 5fa90c2..42325f9 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -337,12 +337,13 @@ func handleIcmpPingTask(task *pb.Task, result *pb.TaskResult) { err = pinger.Run() // Blocks until finished. } if err == nil { - if pinger.Statistics().PacketsRecv == 0 { - result.Data = "Ping 未收到回包" - } else { - result.Delay = float32(pinger.Statistics().AvgRtt.Microseconds()) / 1000.0 - result.Successful = true - } + stat := pinger.Statistics() + if stat.PacketsRecv == 0 { + result.Data = "pockets recv 0" + return + } + result.Delay = float32(stat.AvgRtt.Microseconds()) / 1000.0 + result.Successful = true } else { result.Data = err.Error() }