Detect CPU Speed/Memory/Internet Speed using Java?

14,097

Solution 1

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.

Solution 2

Maybe SIGAR can provide some of the things you need.

Solution 3

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

Share:
14,097
Kirk Ouimet
Author by

Kirk Ouimet

The internet is a miracle.

Updated on June 17, 2022

Comments

  • Kirk Ouimet
    Kirk Ouimet almost 2 years

    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.

  • Kirk Ouimet
    Kirk Ouimet over 14 years
    Hi dr, sorry I should have been more specific, I meant the Java the application language not JavaScript
  • Kirk Ouimet
    Kirk Ouimet over 14 years
    Yeah it seems like Java is very protective over how applications can interact with hardware. The memory stats I saw from the Runtime object are just what the VM will take, not the actual total amount available
  • Tim
    Tim about 12 years
    java testtest.java:3: cannot find symbol symbol : class Properties Properties p = System.getProperties();
  • Arwan Khoiruddin
    Arwan Khoiruddin almost 6 years
    @Tim you should import the Properties first i.e. import java.util.*