处理 ICMP 检测失败的问题,增加特权模式重试。

This commit is contained in:
dushixiang committed 2025-12-06 12:32:38 +08:00
1 parent edf4251310
commit 6374fed87c
1 file changed
+8 -3
+8 -3
View File
@@ -277,9 +277,14 @@ func (c *MonitorCollector) checkICMP(item protocol.MonitorItem) protocol.Monitor
// 执行 Ping
err = pinger.Run()
if err != nil {
result.Status = "down"
result.Error = fmt.Sprintf("ping failed: %v", err)
return result
// 如果非特权模式失败,尝试特权模式(需要 root 权限或 CAP_NET_RAW)
pinger.SetPrivileged(true)
err = pinger.Run()
if err != nil {
result.Status = "down"
result.Error = fmt.Sprintf("ping failed: %v", err)
return result
}
}
// 获取统计信息