Warning: A non-numeric value encountered in /home/ricston2/public_html/blogarchive/wp-content/themes/Divi/functions.php on line 5766

The MMC is a very cool tool for managing Mule instances. It provides a nice functioning GUI with all of the features you would expect for managing your Mule installations.
One very useful feature provided with the product is the alert mechanism. For example; you can define alerts for when your Mule instance peaks 90% of your memory usage and you can also define alerts on JMX attributes.
One disadvantage of MMC is that you can only monitor Mule instances, and nothing else…

A couple of weeks ago I was working on a project where we were required to monitor the size of an ActiveMQ queue. We already had MMC installed and did not want to add another monitoring application. So the the question quickly followed; ‘How can we monitor the queue size from MMC?’ After some pondering, we came up with JMX as the answer.

This is what we came up with:

  1. From Mule, connect to ActiveMQ JMX system
  2. Poll for the JMX attribute value (queue size) every 10 seconds
  3. Publish the value through the JMX of the Mule instance
  4. Monitor the published value from MMC

For step 1, we wrote a very simple Java class:

Although it looks like a lot of coding, there is nothing out of this world going on. In the method checkConnection() we simply connect to the JMX MBean server during initialisation or if we lose the connection. Also, we only connect if the user provides a JMX URL. In the handleNotification() method, if the notification is of type; ‘connection closed’, we set a value to ‘true’ in order to force a re-connection on the next poll. The retrieveMbeanAttribute() method is where all the work is done. Here we first check that we got a connection to the server, then we simply retrieve the attribute using the getAttribute() method.

Configuration of this class in Spring goes something like this:

Having completed step 1, the next step is very easy; we just need a way to poll the method retrieveMbeanAttribute() to update the value of the queue size. For that we chose to use the Spring task scheduler:

Step 3 involves exposing the retrieved value through JMX. The Spring MBean exporter comes in very handy here:

In three easy steps, we managed to retrieve the queue size from ActivMQ and expose that value through the Mule’s JMX system. At this point, the last step is to define an alert on the queue size. This will be shown in part 2 of this blog post. Stay tuned! 😉