Detect CPU Speed/Memory/Internet Speed using Java?

2020-02-01 18:53发布

Is it possible within Java to identify the total CPU speed available as well as the total system memory? Network connection speed to the web would also be awesome.

5条回答
倾城 Initia
2楼-- · 2020-02-01 19:02

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.

查看更多
Anthone
3楼-- · 2020-02-01 19:04
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

查看更多
神经病院院长
4楼-- · 2020-02-01 19:06

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

查看更多
该账号已被封号
5楼-- · 2020-02-01 19:09

Maybe SIGAR can provide some of the things you need.

查看更多
三岁会撩人
6楼-- · 2020-02-01 19:10

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.

查看更多
登录 后发表回答