简体   繁体   English

关于InetAddress的“ isReachable”方法

[英]Regarding InetAddress “isReachable” method

For developing an devices monitor system, I am using a InetAdress isReachable method to know if the device in a network is online or not.I am using the ScheduledExecutorService along with list of devices to ping the icmp devices concurrently. 为了开发设备监控系统,我使用了InetAdress isReachable方法来了解网络中的设备是否在线。我正在使用ScheduledExecutorService以及设备列表来同时对icmp设备进行ping操作。

Now if the devices number is low(say 60 devices) to be pinged by ScheduledExecutorService with a pool of 10 threads,it works fine..Means result will correctly show the device status.Here the isReachable has a time out of 5000 ms. 现在,如果要由ScheduledExecutorService用10个线程池ping的设备数量很少(例如60台设备),则可以正常工作。平均结果将正确显示设备状态。此处isReachable的超时时间为5000毫秒。 If the devices number gets increased say to 80, some devices shows the offline status with isReachable method even if the device is online.If I increase the time out of isReachable method to 10000 ms, the devices status can have better chance to have a correct status. 如果将设备数量增加到80个,则即使设备处于联机状态,某些设备也会使用isReachable方法显示脱机状态。如果我将isReachable方法的超时时间增加到10000 ms,则设备状态可以更有机会获得正确的状态状态。

From these devices, most of the devices are Linux based system and isReachable always return the correct status for them but for Windows, the behavior is unpredictable. 对于这些设备,大多数设备都是基于Linux的系统,并且isReachable始终会为它们返回正确的状态,但对于Windows,其行为是不可预测的。 I want to be sure always of correct status for the devices on a network. 我想确保网络上设备的状态始终正确。 There can also be an alternative mechanism by starting a java process to see the exit value 0 for online devices. 通过启动Java进程来查看联机设备的退出值0,也可以有一种替代机制。

For eg " Process proc = new ProcessBuilder("ping", host).start(); " 例如,“ Process proc = new ProcessBuilder("ping", host).start();

So, what experts will advice? 那么,有什么专家会建议? Will the checking status for a device with a Process as stated above will be more better and reliable than isReachable call? 具有isReachable Process的设备的检查状态是否会比isReachable调用更好,更可靠?

Running ping in subprocesses is unlikely to make things much better; 在子流程中运行ping不可能使情况变得更好。 while there will be less load on the Java process, you're just shifting it around within one machine. 虽然Java进程的负载将减少,但是您只是在一台机器上转移它。 (Furthermore, I'm not sure if you can actually ping multiple machines at once from one host, due to the way that ICMP ECHO — the standardized core of ping — works.) The other issue you're likely to run into is that a machine can be responding to ping without actually being usefully reachable; (此外,由于ICMP ECHO(ping的标准核心)的工作方式,我不确定您是否真的可以一次从一台主机一次对多台计算机执行ping操作。)您可能遇到的另一个问题是一台机器可以响应ping而实际上无法有效地到达它; I've seen machines where the kernel was working (making it pingable) but where there were no working user processes, and you can easily imagine the particular interesting service on the machine being down. 我见过一些机器在运行内核(使其可ping通),但是没有正在运行的用户进程,并且您可以轻松地想象机器上特定的有趣服务正在关闭。 (Also, some firewalls block ping.) It's far better to actually detect if each of the machines is working using some kind of do-nothing connection to the real service running on that machine. (此外,某些防火墙阻止ping。)使用与该机器上运行的真实服务的某种虚连接可以实际检测每台机器是否正常工作,这要好得多。

If you're really looking into keeping track of the status of large numbers of machines, you should look into using software designed for the task (eg, Nagios). 如果您真的想跟踪大量计算机的状态,则应考虑使用为该任务设计的软件(例如Nagios)。 That's much more a question for ServerFault than Stack Overflow… 对于ServerFault而言,这不仅仅是堆栈溢出的问题……

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM