I spent the past 72 hours trying to figure out how to get cpuload (of ALL processes) to my java app, to further work with the numbers.
I need 3 pieces of information: OS, memory usage, and cpuload(1, 5, and 15 minutes) on win and linux. (not java VM usage)
Runtime and Properties classes give me the OS (so i can determine which command to use to gather other info)
i can exec systeminfo and get Total Physical Memory, Available Physical Memory, Virtual Memory Size, Virtual Memory: Available, Virtual Memory: In Use
apparently, there is no way to do this from java on windows (my app has to be portable to at least win and linux) and one has to use C libs and javah to create header files etc.
so, i found this awesome library, and after spending all day building it and getting it to run, it shows the cpu only of the current process.
can anyone help me either modify the existing library or do you have any idea how to get the info done. my homework goes wayyyyy beyond this, but I am stuck right here and see no way out.
I know there exist utilities (and probably even the same command) under the cygwin package for windows (gives a unix-like API and commands to windows boxes through a very functional DLL system) but that does require it to be installed on the client machines unfortunately.. let me see if I can dig something up that's more native....
Not a Java expert (.NET guy here, know just a little bit of Java to be dangerous) - but the obvious solution is to give up portability and either build two versions (Win/Linux) or dynamically load a library with the OS-specific implementation.
EDIT: I guess you have to use JNI to access OS specific implementation... But I can't be sure.
BTW, have you tried googling it? Java "java get cpu load" produces some results.
Java MIGHT be a good example of what a programming language should be like. But Java applications are good examples of what applications SHOULDN'T be like. :laughing:
Linux does not report such thing as CPU load. What you can find out though is % of CPU time spent in varuous states : user code,kernel code, waiting for IO , sleeping
Generally the "load" is defined as number of processes ready to run sampled over fixed time span . Linux uptime gives you that information. You can exec and parse output of that command. On Windows, you can peridocically query process tree for ready to run processes and build avarage yourself.
BTW: take advantage of "information hiding" technique not to get stuck on this particular topic of your homework. Build a stub and move on. You can alway "false" simulate the results when time comes
Generally the "load" is defined as number of processes ready to run sampled over fixed time span . Linux uptime gives you that information. You can exec and parse output of that command. On Windows, you can peridocically query process tree for ready to run. Build avarage yourself.
BTW: take advantage of "information hiding" technique not to get stuck on this particular topic of your homework. Build a stub and move on. You can alway "false" simulate the results when time comes
/proc/cpuinfo is just going to show you information on the processor like family, model, cache size, etc n shit it wont show you its load. so you cant really 'grep' that and expect to get the info you're looking for
now, but if I in my logic make use of the library only in case my OS is let's say "win", and don't make any use of it in other case, I should be fine, right?
this C++ lib is made for win, the other, first one I found was generic, but it gave me just the cpu usage of the current process.
if I can get my info by exec command on linux, I won't need the library.
Thank you Diesel boy!
now, but if I in my logic make use of the library only in case my OS is let's say "win", and don't make any use of it in other case, I should be fine, right?
sure, i know about it, but i would have to install it on every single client i need to run the app at. so that wouldn't make the app as portable as if i was using csv or xml
but thanks anyway
i demonstrated that it worked, and a couple of us got an extension to work on gui. that's good news!!!
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Related Threads
?
?
?
?
?
Chicagoland Sportbike Forums
2M posts
11.3K members
Since 2002
A forum community dedicated to Chicagoland Sportbike owners and enthusiasts. Come join the discussion about performance, modifications, classifieds, troubleshooting, maintenance, and more!