• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get CPU and Memory idle values using Java?

 
Chetan Parekh
Ranch Hand
Posts: 3640
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henry Wong
author
Marshal
Pie
Posts: 20826
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Arjun K
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 3640
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for useful link
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic