4 Replies Latest reply on May 28, 2011 3:14 AM by jtahlborn

    How to get a System's total CPU usage percentage


      I need to find the system's total CPU usage percentage ( as we see in Windows Task Manager) using a java program. I am able to find the CPU usage time for one process using the OperatingSystemMXBean API. But i am not able to find a way to find the CPU usage percentage for all the process running on a system.
      I cannut use any third party tools to acheive this. Are there any third party jars available which can help me in getting this data?

        • 1. Re: How to get a System's total CPU usage percentage
          One possibility is to use ProcessBuilder to execute

          "tasklist /FO CSV"

          and then parse the 'stdout'. You might find the CPU time resolution too small for you but ...

          Note - you should read the 4 sections of http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html and implement ALL the recommendations. Though the article is written round Runtime.exec() the traps apply to the Process object however it is created.
          • 2. Re: How to get a System's total CPU usage percentage
            i guess jniwrapper libs allow you to do such thing. however it will be native impl and jni calls.
            on a side note, do consider # of processors as well. these days most of the machines will have multiple cores.

            • 3. -deleted-

              Edited by: BIJ001 on 27-May-2011 05:39
              • 4. Re: -deleted-
                you might want to check out the SIGAR library, http://support.hyperic.com/display/SIGAR/Home . we were looking for functionality like this and came across this library. in the testing i did, it seemed to work great, although we never ended up implementing the features which required it, so i never actually used it for real.