views:

1376

answers:

4

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.

A: 

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

dr
Hi dr, sorry I should have been more specific, I meant the Java the application language not JavaScript
Kirk
A: 

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.

Jim Ferrans
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
Kirk
A: 

Maybe SIGAR can provide some of the things you need.

fulkod
+2  A: 

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.

Brian Agnew