Luis-Miguel Alventosa's Blog

All | Java | xVM
« Securing the out-of-... | Main | Enhanced JTop JConso... »
20070202 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)

Per-thread CPU Usage JConsole Plugin

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:

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]

Trackback URL: http://blogs.sun.com/lmalventosa/entry/per_thread_cpu_usage_jconsole
Comments:

This demo is very useful to add our own tab to their existing tab.

Posted by Raghavanantham.V on February 22, 2007 at 11:27 AM CET #

I have been using JDK6 Jconsole and plugins to run against JDK5 runtimes. I compiled and ran your code against a JDK5 runtime and received a: java.lang.reflect.UndeclaredThrowableException when calling: threadProxy.dumpAllThreads(flase,false)

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 #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed

Calendar

RSS Feeds

Search

Links

Planet JMX

Navigation

Referers