Finding Average CPU Usage for a Windows Machine in Java

I searched all over the internet for about two days. I learned a lot about how to find CPU usage using VB and anything in the .NET platform. I do not use the .NET platform, so I do not understand.

I really need results similar to those shown in the CPU Usage section of the Windows Task Manager on the Performance tab. If I could find a way to imitate these calculations, then this is exactly what I am looking for. I need a percentage of CPU usage.

Obviously, Java is not an ideal language for finding CPU usage on a computer, but it is the language that I use, and I was able to get everything else I need for a computer other than that.

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

This is the first time I have asked a question, so if I left something or something is unclear, ask and I will do my best to explain more than what I have in mind.

+4
source share
1 answer

There are several ways to do this; one is to run a command line tool and analyze 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 .

+3
source

Source: https://habr.com/ru/post/1483617/


All Articles