This is basically an all-in-one repository for techie developer-related things I've experienced / come-across and from where I can easily look-up later.
From small useful tidbits, code / key shortcuts, tips, to articles /guides on how to do certain complicated tasks, all the way to full mini-programs for daily use.
If it helps anyone else out too great!

Friday, October 24, 2008

Here's some insights and tips on accessing the JMX Agent using JConsole.

JConsole is the most handy way to connect and test your JMX services since it comes with every JDK from Java 5 onwards. If you have your jdk/bin directory included in your path, it's just a matter of running it from a command prompt by typing:jconsole

Its usage is pretty straightforward too. Once it's loaded, you can choose to connect from one of 3 options: Local, Remote and Advanced - there's one tab for each of these.

Local - If you had registered your MBeans with the default JVM's MBean Server, select the Local tab. Here, the MBeans will be automatically displayed and all that needs to be done is to click on Connect.

Remote - I find Advanced is actually simpler than this tab - so skipping this...

Advanced - If you had registered your MBean from an application that you deployed on a J2EE server (like Sun One), then there are a few more steps as you have to use the Advanced tab.

Obtain your JMX connection URL either from the admin console or the server.log (it appears right after the server start-up entry - something like service:jmx:rmi:///jndi/rmi://localhost:8686/management/rmi-jmx-connector).

Type this into the JMX URL field.

Enter your server's username and password into those respective fields as well and click connect.

That's it! You're connected. You'll see a whole array of information - there's a chance you'd get overloaded! Head on over directly to the MBeans tab - here you can view all the MBeans successfully registered on this MBeanServer, in the Tree view on the left. Again, don't worry if you can't find yours at first - there might be lots of internal MBeans that the server registers that are crowding the list. Your MBean should appear in its fully qualified form, i.e. <<packagename>>.<<classname>>. Its pretty straightforward from here on - you can easily find your exposed methods / attributes and invoke / change them too.

Ok, seemed pretty easy but in real life, you would most probably run intos ome hiccups even before connecting. Most are obvious enough from the error messages. But what if you needed more details than one-line messags to troubleshoot? Unfortunately, the default Jconsole messages are not very helpful.

This is where you have to override the default values to get full stacktraces and much more.This is a simple 2 step process:

2 comments:

The JMX connection URL would appear differently on the admin console of different app servers. But no matter which app server, the jmx server url will appear in the startup logs if it is enabled. So I suggest you take that route.