2

I'm currently writing a Java application that needs to look at how "heavily loaded" the machine it's running on is. On *nix, load average divided by number of processors fits the bill perfectly, and we retrieve load average with ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage(). Unfortunately, this returns -1 on Windows, as the call is apparently too "expensive" to be called frequently. What's the easiest way to retrieve similar Windows metrics such as the processor queue length or CPU utilisation, either in pure Java or via JNI?

3 Answers 3

3

You can retrieve the CPU utilization on Windows using WMI. Some code and documentation for accessing WMI from Java appears to be available here.

Sign up to request clarification or add additional context in comments.

5 Comments

Or even easier, use the wmic interface!
I've always been a fan of do it in code over invoking an external program, but wmic seems useful.
WMI looks like what I'm after. I don't think I'll go down the J-Integra route, though - I'm thinking of using code from henryranch.net/software/jwmi-query-windows-wmi-from-java , although I'm still on the lookout for something that calls it programatically (this one creates a VBScript dynamically).
@Anders, could you please show me how to do it? J-integra is not free software.
@eric2323223 wmic is a native Windows scripting interface for WMI (if WMI exists on a host - so does wmic), just invoke it through your Java application.
2

Try using the free Hyper SIGAR API. It is a cross platform API for calling system information. It uses JNI for Windows/Linux/Unix/Mac/etc.

http://www.hyperic.com/products/sigar

I wrote a JNLP task manager/information monitor with it and it's a decent API.

http://www.goliathdesigns.com/2009/12/sixth-post/

Source code:

http://sourceforge.net/projects/sysinfomonitor/

Comments

0

You can also perfom this task using Eclipse SWT if you are running on an win32 environment:

http://dentrassi.de/2011/02/04/access-to-wmi-in-java-using-eclipse-swt-ole-integration/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.