aspose file tools*
The moose likes Distributed Java and the fly likes Geting the CPU usage of a machine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Geting the CPU usage of a machine" Watch "Geting the CPU usage of a machine" New topic
Author

Geting the CPU usage of a machine

Sultan Al-Yahyai
Greenhorn

Joined: Nov 07, 2004
Posts: 7
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
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
Cool - just this morning a reference to this article on getting at Windows Performance data appeared in my inbox.
If you try it, please let us know how it works for you.
Bill
kk zhu
Greenhorn

Joined: Nov 21, 2004
Posts: 1
I can use NSClient package to get cpu usage on win32 platform, but it can't support Solaris OS.
Does anyone extend it to support unix/linux OS?

Originally posted by William Brogden:
Cool - just this morning a reference to this article on getting at Windows Performance data appeared in my inbox.
If you try it, please let us know how it works for you.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Geting the CPU usage of a machine