This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Hi all, I want to find the CPU usage of a machine in the network or the localhost. is that possible in Java? if so please help, otherwise if any one know a utility to do so please tell me. things also such as available memory / hard disk ... are intersting to me as well
There isn't a built in way to get the CPU usage in Java... you'd have to write code in C (or some other language) and use JNI to call the C program, or use Runtime.exec() to call an existing program that gives you this information. Here's a JavaWorld article about this.
There is also no built in way to get the available free space on the hard drive... you're once again stuck calling a system command through Runtime.exec(), using JNI to a program in another language, or using this ugly workaround code posted in Sun's forums.
And again there is no built in way to get the total/free RAM memory in the system either... you can call Runtime.totalMemory() and Runtime.freeMemory() but they just report on memory available inside the JVM. So once again, you are stuck writing something in native code, or using Runtime.exec() to call a command line utility.
The reason that none of these things are available in Java is because Java runs in a virtual machine that is independent of hardware, and all of these functions are a little "too close to the metal"...
As far as how to distribute them to work on "any machine in the network, or the localhost", you'd need to implement a little RMI server that would do these functions and run it on each machine. Then you could write a client application that would query a specified machine to return the data that was asked for.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.