zxl
2025-03-03 eb0e29e72049bc65f943cc864929c332b07f25d0
ycl-server/src/main/java/com/ycl/utils/CheckPointUtil.java
@@ -61,7 +61,6 @@
            res = selfHttpUtil.get(prefix + monitor.getIp(), null, null);
            monitor.setPingOnline(Objects.nonNull(res) && HttpStatus.OK == res.getStatusCode());
        } catch (Exception e) {
            log.error("web检测离线"+monitor.getIp());
            monitor.setPingOnline(Boolean.FALSE);
        }
        // 如果http得到的不在线,那么再ping一下
@@ -86,12 +85,7 @@
            map = new HashMap<>();
        }
        if (!monitor.getPingOnline()) {
            try {
                reachable = InetAddress.getByName(monitor.getIp()).isReachable(5000);
            } catch (IOException e) {
                log.error("Ping异常{}",e.getMessage());
            }
            if(!reachable) log.error("ping检测离线"+monitor.getIp());
            reachable = checkPing(monitor, reachable);
            monitor.setPingOnline(reachable);
        }
        if (!monitor.getPingOnline()) {
@@ -123,6 +117,22 @@
        return monitor;
    }
    private boolean checkPing(TMonitorResult monitor, boolean reachable) {
        try {
            int[] sleepTimes = {5000, 15000, 30000};
            for (int sleepTime : sleepTimes) {
                reachable = InetAddress.getByName(monitor.getIp()).isReachable(5000);
                if (reachable) {
                    break;
                }
                Thread.sleep(sleepTime);
            }
        } catch (Exception e) {
            log.error("Ping异常",e);
        }
        return reachable;
    }
    /**
     * 监测点位在线