4

I have searched all over the internet for about two days now. I have found a lot about how to find the CPU usage using VB and anything in the .NET framework. I am not using the .NET framework so these are irrelevant, I feel.

What I really need is results similar to the ones shown in the "CPU Usage" section in a Windows Task Manager under the "Performance" tab. If I could find a way to mimic that calculation, then that is exactly what I am looking for. I need the percentage of CPU Usage.

Obviously, Java is not the ideal language for finding the CPU usage of a computer, but that is the language I am using and I have been able to get everything else I need about the computer except this.

I am using Windows 7 with Java version 7 update 21. Eclipse is my IDE.

This is my first time posting a question on here, so if I have left anything out or something is not clear, please ask and I will do my best to explain more of what I mean.

HighHopes
  • 2,014
  • 3
  • 23
  • 33
  • http://stackoverflow.com/questions/47177/how-to-monitor-the-computers-cpu-memory-and-disk-usage-in-java possible duplicate – DGomez May 30 '13 at 15:54
  • @DGomez I tried using the SIGAR API that is mentioned in that answer that you posted, and I was able to get the memory of the computer and a few other things, but I am still not sure how to get the average CPU Usage. Maybe I just need some help in SIGAR API. What do you think? – HighHopes May 30 '13 at 16:02

1 Answers1

3

There are a couple of ways to do this; one is to run a command-line tool and parse the output. On Windows 7, you can run

c:\Windows\system32\typeperf "\processor(_total)\% processor time"

Try it -- it prints a few lines of sampled CPU load data.

Another way is to use OperatingSystemMXBean .

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186