Wednesday March 15, 2006 ![]() |
JMX, SNMP, Java, etc...Daniel Fuchs blogs on JMX, SNMP, Java, etc... |
...Danny Coward recently wrote an excellent blog about the various Java SE 5.0 and Java SE 6 tools that will help you diagnose problems in your Java application. As an exercise, I have written a little Java application that will let you dynamically activate your own traces in a running Java application ... A few days ago - I blogged about Tracing JMX - to see what's happening in the MBeanServer, and showed how to dynamically activate the JMX traces in a running Java application. I have taken this example a step further, and wrote a small command line console that uses JMX to let you:
all of this dynamically from a command-line tool. For this all I had to do was to write a
JMXTracingCLI class - which simply reuses the
Activate, JMXTracing, and JMXTracingMBean classes I was using in my example last week. The JMXTracingCLI is a simple command line
interpreter that attach to existing VMs and then use JMX to tweak the
logging configuration in the target VM. If you create a NetBeans project (named tracing) with all these
classes, choose Java SE 6 as Java Platform, add Java SE 6 tools.jar to the
project libraries, and choose
com.sun.jmx.examples.util.tracing.JMXTracingCLI as Main class for this
project, NetBeans will create for you a dist/tracing.jar file that you
will be able to execute directly from the java command line. For instance this is an example of what it can do: Start the command line tool
The following help is displayed:
list the known VMs:
I have two Java SE 6 VMs running on my machine: my tracing tool, and my NetBeans IDE [yes, I'm fearlessly using NetBeans with Java SE 6 - all you need to do is to start NetBeans with the appropriate --jdkhome switch]. I'm now going to attach to NetBeans IDE VM. But before I do so, in another terminal I'm going to display NetBeans log file:
Then I go back to my JMXTracingCLI and attach to NetBeans VM:
OK, the tool tells me that console is off. So I'm going to register a new ConsoleHandler in the target VM.
I want to get swing loggers:
Hummm... Only two. Let's switch them to FINEST
If now run my mouse over NetBeans, I can see that the swing traces I just activated are dumped in the log:
This example could be taken even further by e.g. improving the JMXTracingMBean
and JMXTracingCLI to make the target VM spit out its traces on a temporary
file on e.g. /tmp, instead of simply enabling Console output.
Cheers, Tags: java jconsole jmx jvm Posted by dfuchs ( Mar 15 2006, 06:01:56 PM CET ) Permalink Comments [0] |