• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can i get the CPU usage through Java program

 
RAVI Kollepara
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi coffeebeans,
I am having the requirement to get the CPU usage of the machine where my java application is running. Not only that, i need to show the memory usage etc., statistics. Is there any solution for this problem.
I can issue a TOP command on linux and get the output but it should be platform independant.
Any help???
Thanx
Ravi Kollepara
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there is a way for you to get these information using pure Java. There might be some JNI libraries that can get this info, which you can use it in your Java application.
This way, your application will be platform independent, but you need different JNI libs for different platforms.
 
Joe Ess
Bartender
Posts: 9337
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No way to do it platform independent, but if you are on Linux, you should know about the proc filesystem. The information you seek and much, much more is available there in a simple text file format. So simple to use you will curse other OS's that keep that information under the hood.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google finds the following article: http://www.javaworld.com/javaworld/javaqa/2002-11/01-qa-1108-cpu.html
 
RAVI Kollepara
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi preuss,
But the example says abt win 32 application. Can u give me the JNI example for Linux O/s . Is there any possiblity to give a solution which has to work independant of platform?
Anyway Thanx for showing a window to my problem.
Ravi Kollepara
 
Kris Philippaerts
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by RAVI Kollepara:
Is there any possiblity to give a solution which has to work independant of platform?

No, there isn't. If you want to use it on different platforms, you will have to write JNI library for every platform. As posted before, on Win32 you can use the Win32 API, and on Linux (and other unices) you can use the proc filesystem to do this.

Regards,
Kris
[ June 21, 2004: Message edited by: Kris Philippaerts ]
 
Aaron Roberts
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much Ilja!! I was trying to do just this recently. I asked the question here at the ranch, can't remember where and just got the - you'll need jni response. I now have a solution!!

Thanks,
Aaron R>
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're very welcome!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic