| | |
| | | ResponseEntity<String> res = null; |
| | | String prefix = "http://"; |
| | | if ("127.0.0.1".equals(monitor.getIp())) { |
| | | monitor.setOnline(Boolean.FALSE); |
| | | monitor.setPingOnline(Boolean.FALSE); |
| | | return monitor; |
| | | } |
| | | try { |
| | | res = selfHttpUtil.get(prefix + monitor.getIp(), null, null); |
| | | monitor.setOnline(Objects.nonNull(res) && HttpStatus.OK == res.getStatusCode()); |
| | | monitor.setPingOnline(Objects.nonNull(res) && HttpStatus.OK == res.getStatusCode()); |
| | | } catch (Exception e) { |
| | | monitor.setOnline(Boolean.FALSE); |
| | | monitor.setPingOnline(Boolean.FALSE); |
| | | } |
| | | // 如果http得到的不在线,那么再ping一下 |
| | | boolean reachable = false; |
| | |
| | | } else { |
| | | map = new HashMap<>(); |
| | | } |
| | | if (!monitor.getOnline()) { |
| | | if (!monitor.getPingOnline()) { |
| | | try { |
| | | reachable = InetAddress.getByName(monitor.getIp()).isReachable(5000); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | monitor.setOnline(reachable); |
| | | monitor.setPingOnline(reachable); |
| | | } |
| | | if (!monitor.getOnline()) { |
| | | if (!monitor.getPingOnline()) { |
| | | offLineTimes++; |
| | | } |
| | | map.put("checkTimes", checkTimes); |