File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to get CPU and Memory idle values using Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get CPU and Memory idle values using Java?" Watch "How to get CPU and Memory idle values using Java?" New topic
Author

How to get CPU and Memory idle values using Java?

Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
Hello,

I want to measure the Memory and CPU utilization of over App Server.

I decided to write a Thread in java that will be activated after each 15 min.

Now my problem is that, how to get CUP and Memory idle value at the given point of time using Java?

Reg,
Chetan


My blood is tested +ve for Java.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18977
    
  40

Unfortunately, if you are looking for system data, it is not available directly from the JVM. If I remember correctly, you might be able to get free memory, but even that, I don't think is free memory at an OS level.

The easiest way to get the info is to do a system exec to the appropriate OS command and parse the results. For Unix, the command is "vmstat", or examining the "/proc" file system. For Windows, the command is "typeperf".

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Arjun K
Ranch Hand

Joined: Mar 09, 2005
Posts: 39

Taken from Henry Wong post:
Unfortunately, if you are looking for system data, it is not available directly from the JVM. If I remember correctly, you might be able to get free memory, but even that, I don't think is free memory at an OS level.


I assume that you are touching on the situation prior to J2SE 1.5

Yes the java.lang.management package is the answer, that has been introduced in Tiger.
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/package-summary.html

Good starting point is to play with jConsole:

http://java.sun.com/j2se/1.5.0/docs/guide/management/

HTH,
Arjun K
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
Thanks for useful link
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get CPU and Memory idle values using Java?