Friday February 02, 2007 Per-thread CPU Usage JConsole Plugin
JConsole plugin that allows to plot the CPU usage of a set of threads running in a remote VM. It could be seen as an add-on to the existing JTop JConsole plugin in Java SE 6 (<JDK6_HOME>/demo/management/JTop). The aim of this plugin is to show how easy it is to add a custom UI to JConsole based on the Java SE platform instrumentation MXBeans in conjunction with the JFreeChart chart library.
Before going into the implementation details let's see how this new JConsole tab looks like:
(this example monitors the CPU consumption of the threads GreedyThread-1 and GreedyThread-2)
This JConsole plugin is made of two Java classes:
The main differences between the standalone Swing-based application and the JConsole plugin are the following:
JFrame. The getTabs() method in the JConsolePlugin class is called to retrieve a JPanel for each of the tabs to be added to JConsole.newSwingWorker() method in the JConsolePlugin class is called at the same interval as JConsole updates the GUI.META-INF/services/com.sun.tools.jconsole.JConsolePlugin. This file must contain one line for each plugin. The TheadCpuUsage.jar file contains a single plugin so it defines the line com.sun.example.ThreadCpuUsagePlugin.Have a look at the readme.txt file in the resource bundle for more detailed info on how to use this plugin. The source code is also included in the bundle.
Posted by lmalvent ( Feb 02 2007, 04:43:11 PM CET ) Permalink Comments [5]
Posted by Raghavanantham.V on February 22, 2007 at 11:27 AM CET #
I made the following change to that line of ThreadCpuUsage.updateTimeSeries():
< ThreadInfo tis[] = threadProxy.dumpAllThreads(false, false);
---
> ThreadInfo tis[] = threadProxy.getThreadInfo(threadProxy.getAllThreadIds()) ;
This change allows me to run your code in JDK6 Jconsole against JDK5 runtimes.<> Thanks for putting this together and posting this.
Posted by Michael Ottati on March 28, 2007 at 12:35 AM CEST #
This is excellent trend from sun to improve jmx management, will be nice if there are more samples like this from you.
Posted by Larry on January 07, 2008 at 04:02 AM CET #
Hi Luis-Miguel,
I'm looking for a way to compute the global CPU Usage of my JBoss Server. Do you think I can find an easy solution by reading the JConsole sources (about CPU Usage) ? Maybe this sources are not accesibles ?
Cordially
Antoine Verger
Posted by Antoine Verger on May 14, 2008 at 04:51 PM CEST #
Hi Antoine, the JConsole source code is available at http://openjdk.java.net.
Posted by Luis-Miguel Alventosa on May 26, 2008 at 02:03 PM CEST #