Detect CPU Speed/Memory/Internet Speed using Java?

允我心安 提交于 2019-11-28 01:52:59

This really depends on your OS, since Java will tell you little about the underlying machine. Unfortunately you have to use differing approaches depending on your OS.

If you're on Linux, take a look at the /proc/cpuinfo filesystem for CPU info. /proc generally has a wealth of information. Network (IO) will be reflected via the command ifconfig.

If you're on Windows, a useful tool is WMI, which provides access to all sorts of low-level hardware stats. You can run WMI scripts via CScript. Here's a page of examples of WMI scripts.

Maybe SIGAR can provide some of the things you need.

Properties p = System.getProperties();   
    p.list(System.out); 
    System.out.print("Total CPU:");
    System.out.println(Runtime.getRuntime().availableProcessors());
    System.out.println("Max Memory:" + Runtime.getRuntime().maxMemory() + "\n" + "available Memory:" + Runtime.getRuntime().freeMemory());
    System.out.println("os.name=" + System.getProperty("os.name"));

try above

Memory stats are available from the Runtime object. And take a look a jconsole, a graphical client that presents information about a JMX-enabled Java Virtual Machine. It shows a lot of information including CPU usage, so you could write your own client that accesses the JMX information too.

JPU might give you CPU. And this link might help too

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!