There is a Java library running on windows machines that needs to log information about the OS like CPU load, memory occupied by the JVM etc. which I'm quite sure Java itself cannot obtain, because it is OS specific.
This information is needed in the logs of this library in order to point out to clients that certain operations failed because the library could not obtain enough resources.
It is not possible to choose the JVM, i.e. we cannot demand that our clients should use a specific JVM that does implement windows OS specific functionality.
Is there a windows library (DLL) or API that could be used via JNI?
We could also implement a DLL in C++ or C# ourselves, where would I need to look to see how this could be done most effectively?
Edit: I need access to data about the process of the JVM itself, which I can get through the native Windows API only, I guess. So I think I'll have to implement a small C program and link this as native DLL via JNI. Any tips on that?
For the memory part, look at several memory related methods of the Runtime. To get the occupied memory, try the following:
I have not tried this yet, but for the CPU load take a look at the following. The
getSystemLoadAverage()
method should do it.Hope this helps!