Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > retrieving CPU Usage and Memory Usage information in JAVA

Reply
Thread Tools

retrieving CPU Usage and Memory Usage information in JAVA

 
 
hvt
Guest
Posts: n/a
 
      03-13-2007
Hi All,
I 've been searching through this group for information on CPU and
Memory usage retrieval on Windows machine using JAVA. After following
so many previous threads on the same subject, the possible solution I
've observed was using JNI calls to native libraries for these OS
specific information retrieval.
Later I found that java management libraries already has it, native
libraries and some jmx classes.

Sharing the code, hope this may help group members in their
requirements.

Code:
com.sun.management.OperatingSystemMXBean mxbean =

(com.sun.management.OperatingSystemMXBean)
ManagementFactory.getOperatingSystemMXBean();

System.out.println("********* CPU & MEMORY USAGE OF \\harsh
*********");
System.out.println("OS : "+mxbean.getName());
System.out.println("Available Processors :
"+mxbean.getAvailableProcessors());
System.out.println("Commited Virtual Memory :
"+mxbean.getCommittedVirtualMemorySize());
System.out.println("Free Physical Memory :
"+mxbean.getFreePhysicalMemorySize());
System.out.println("Free Swap Space Size :
"+mxbean.getFreeSwapSpaceSize());
System.out.println("Process CPU Time : "+mxbean.getProcessCpuTime());
System.out.println("Total Physical Memory Size :
"+mxbean.getTotalPhysicalMemorySize());
System.out.println("Total Swap Space Size :
"+mxbean.getTotalSwapSpaceSize());

Problem:
getProcessCpuTime() method returns the CPU time used by the process on
which the Java virtual machine is running NOT the '%CPU Usage' time
which i was hoping to get.

If anyone is having idea about how to obtain '%CPU Usage' of windows
machine using java program, kindly post the message.

Regards,

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CPU Usage frequently 100% even though it seems not even close tototal memory Newcomer Computer Support 3 11-15-2009 06:51 AM
CPU Usage frequently 100% even though it seems not even close tototal memory Newcomer Computer Support 0 11-14-2009 11:21 PM
Cisco 6500 / Sup32 high CPU and memory usage seanblee Cisco 0 01-26-2009 11:30 AM
retrieving CPU Usage and Memory Usage information in JAVA hvt Java 0 03-13-2007 01:09 PM
LF JMX reference implementation on VM CPU/memory usage instrumentation Wenbo Java 0 02-17-2004 06:59 PM



Advertisments