This discussion is archived
5 Replies Latest reply: Jun 25, 2010 12:01 AM by PhHein RSS

JConsoles CPU Usage graph

843798 Newbie
Currently Being Moderated
We have Server applications implemented with MBeanServers. We also have various monitoring applications for these servers (like Nagios). We want to grab the CPU usage value that JConsole displays on these servers. In digging through all of the MBeans on JConsole's MBean tab pane, I can not seem to find an attribute that reflects that same value shown on the Overview tab panes CPU graph.

The java.lang domains OperatingSystem.Attributes.SystemLoadAverage looked promising but it�s values do not match that of the graph, and don�t seem to follow what the CPU is doing.

Can anyone please tell me how you get the CPU utilization value?

Thanks!!

Edited by: timpanogos on Jun 13, 2008 8:22 AM
  • 1. Re: JConsoles CPU Usage graph
    843798 Newbie
    Currently Being Moderated
    JConsole's CPU usage graph is computed as follows:
            ...
            long elapsedCpu = result.processCpuTime - prevProcessCpuTime;
            long elapsedTime = result.upTime - prevUpTime;
            // cpuUsage could go higher than 100% because elapsedTime
            // and elapsedCpu are not fetched simultaneously. Limit to
            // 99% to avoid Plotter showing a scale from 0% to 200%.
            float cpuUsage =
                Math.min(99F,
                         elapsedCpu / (elapsedTime * 10000F * result.nCPUs));
            ...
    where:

    * processCpuTime: com.sun.management.OperatingSystemMXBean.getProcessCpuTime()
    * upTime: java.lang.management.RuntimeMXBean.getUpTime()
    * nCPUs: java.lang.management.OperatingSystemMXBean.getAvailableProcessors()

    JConsole is open source and the code is available in the OpenJDK site.

    Have a look at the java class sun/tools/jconsole/SummaryTab.java.

    Regards,
    Luis-Miguel Alventosa - JConsole dev team
  • 2. Re: JConsoles CPU Usage graph
    843798 Newbie
    Currently Being Moderated
    Luis-Miguel,

    Thank you for answering my question! I had looked for the open source JConsole, but somehow missed it ... I'll go look again. I was able to implement based on the information you gave me and it works great.

    Somehow, when I registered, my screen name got messed up (notice this is timpanogos1, not the original timpanogos) ... I've posted an enquiry to get this fixed so I can award you your points and mark this question answered.

    Thanks again for you prompt response ... much appreciated!


    P.S. Feedback - Sun Microsystems FID:18088

    Edited by: timpanogos1 on Jun 14, 2008 9:33 AM
  • 3. Re: JConsoles CPU Usage graph
    843798 Newbie
    Currently Being Moderated
    Thanks again ... finally got my account straight and marked this as answered correct
  • 4. Re: JConsoles CPU Usage graph
    843798 Newbie
    Currently Being Moderated
    Can You tell me from where to download com.sun.management package ?

    Thanks
  • 5. Re: JConsoles CPU Usage graph
    PhHein Guru Moderator
    Currently Being Moderated
    Welcome to the forum. Please don't post in threads that are long dead and don't hijack other threads. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.

    I'm locking this thread now.