Remote JMX Monitoring of a Mule Instance
Remote JMX Monitoring of a Mule Instance
Join the DZone community and get the full member experience.Join For Free
Learn more about how to Prevent Slow or Broken APIs From Affecting Your Bottom Line.
In this post I will describe how to enable monitoring of a remote Mule instance using JMX. In addition I will also enable the MX4J web interface that will expose the JMX properties of the Mule instance in a web application and I will install the Jolokia Mule agent, which makes it possible to use Hawtio to monitor the Mule instance.
Enabling JMX for a Mule Instance Using a Mule Application
As of writing this, the finest granularity for which JMX monitoring can be enabled is an entire Mule instance. Thus it is not possible to enable JMX monitoring per application basis in a Mule instance.
This of course has advantages and disadvantages and we are going to use this fact to our advantage by deploying an application to a Mule server that does nothing but enable JMX monitoring for the server.
- Create a directory named “MuleJMXEnabler”.
- In this new directory, create a file named “mule-config.xml” with the following contents:
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:management="http://www.mulesoft.org/schema/mule/management" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/corehttp://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/managementhttp://www.mulesoft.org/schema/mule/management/current/mule-management.xsd"> <management:jmx-server> <management:connector-server url="service:jmx:rmi:///jndi/rmi://192.168.1.73:1096/jmxrmi"/> </management:jmx-server> </mule>
- In the above file, replace the IP address “192.168.1.73” with either the external IP address or the DNS name of the computer running the Mule server that you want to monitor.
- Optionally, you may change the port number 1096 to any port that you rather use.
- Deploy the application by copying the directory MuleJMXEnabler with its contents to the apps directory of the Mule instance that is to be monitored.
- Verify that the application was successfully deployed in the log of the Mule instance (mule.log if you are using the community edition, mule_ee.log if you are using the enterprise edition).
You should see something like this:
INFO 2014-08-24 16:24:24,009 [Mule.app.deployer.monitor.1.thread.1] org.mule.module.launcher.MuleDeploymentService: ================== New Exploded Application: MuleJMXEnabler INFO 2014-08-24 16:24:24,010 [Mule.app.deployer.monitor.1.thread.1] org.mule.module.launcher.application.DefaultMuleApplication: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + New app 'MuleJMXEnabler' + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ INFO 2014-08-24 16:24:24,668 [Mule.app.deployer.monitor.1.thread.1] org.mule.module.launcher.MuleDeploymentService: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Started app 'MuleJMXEnabler' + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The above is the minimum configuration that I need to enable remote JMX access to a Mule instance.
Try connect to the Mule instance using some JMX monitoring application, like JVisualVM or Java Mission Control. The following steps describe how to do when using Java Mission Control:
- Launch Java Mission Control.
- Right-click in the JVM Browser pane and select New Connection.
- In the Host field, enter the IP address or DNS name that you used earlier in the mule-config.xml file.
In my case that will be “192.168.1.73”.
- In the Port field, enter the port number that you also entered in the mule-config.xml file earlier.
In my case it was “1096”.
- Click the Test connection button.
The status should be reported as OK as in this picture.
- Click the Finish button.
You are now ready to connect to the MBean Server of the Mule instance and start monitoring it.
This approach has the advantage of allowing modifications to the JMX configuration of a Mule instance without having to restart it. If I want to make any modifications to the JMX configuration, enable or disable JMX in the Mule instance I just edit the mule-config.xml file in the apps/MuleJMXEnabler directory in the Mule instance home and save it. If hot deployment has not been disabled, the Mule server will automatically re-deploy the application and pick up the changes.
Enabling JMX for a Mule Instance Using Wrapper Parameters
One alternative for enabling JMX monitoring of a Mule instance that I have had success with is to add a set of Java VM parameters in the wrapper configuration file of the Mule instance.
The wrapper configuration file is named “wrapper.conf” and can be found in the conf directory of the Mule instance.
To enable remote JMX access, add the following additional JVM parameters to your wrapper.conf file:
# Enables remote JMX management without authentication or SSL over port 1096. wrapper.java.additional.4=-Dcom.sun.management.jmxremote wrapper.java.additional.5=-Dcom.sun.management.jmxremote.port=1096 wrapper.java.additional.6=-Dcom.sun.management.jmxremote.authenticate=false wrapper.java.additional.7=-Dcom.sun.management.jmxremote.ssl=false wrapper.java.additional.8=-Djava.rmi.server.hostname=192.168.1.73
- You MUST adjust the numbering of the additional JMV parameters, as described in the comments in the wrapper.conf file!
Thus 4, 5, 6, 7 and 8 may not be the correct numbers for your wrapper.conf file.
- You must change the IP address to the remote IP address of the computer on which the Mule server is running.
- You may want to change the port number.
- The Mule instance must be restarted after the modifications, in order for them to come into effect.
The drawback with this approach is that the Mule instance needs to be restarted each time there is a modification to the JMX-related configuration parameters.
With the target computer running Mac OS X, I need to chose one of the two described ways to enable remote JMX monitoring – if I use wrapper parameters, the MuleJMXEnabler application will not start properly.
On Ubuntu I can chose either of the two approaches but was also able to use both approaches simultaneously without errors.
Enabling the MX4J Web Interface
If you are using the first approach, enabling JMX using a Mule application, then adding the following XML element to the mule-config.xml file as a child element of the <mule> element enables the MX4J web interface exposing the JMX beans of the Mule instance in question:
<management:jmx-mx4j-adaptor jmxAdaptorUrl="http://192.168.1.73:1100"> </management:jmx-mx4j-adaptor>
As before, the IP address needs to be changed to the external IP address of the computer on which the Mule instance is run. The port number may be changed from 1100 to any free port that you rather use.
The MX4J web interface may, in my case, then be accessed using the URL http://192.168.1.73:1100.
Install the Jolokia Mule Agent
With the first approach to enable JMX in a Mule instance described above, you can also enable Jolokia – the JMX-to-HTTP bridge which enables use of the Hawtio – an extensible web-based management console for Java applications.
Version 1.2.2 of the Jolokia Mule agent, which at the time of writing is the latest, does not work with Mule 3.5 due to the Jetty libraries having been updated from version 6 to version 8.
In this example I used Mule 3.4, which is the latest version of Mule that still use the Jetty 6 libraries, as far as I know.
- Download the Jolokia Mule agent from http://www.jolokia.org/download.html
- Move the agent JAR file to the lib/opt directory in the Mule instance that you want to monitor.
- Add the following configuration as a child element of the <mule> element in the mule-config.xml of the MuleJMXEnabler application created earlier:
The port number may be modified as desired.
<custom-agent name="jolokia-agent" class="org.jolokia.mule.JolokiaMuleAgent"> <spring:property name="port" value="1095"/> </custom-agent>
- Open the URL http://192.168.1.73:1095/jolokia/ in a web browser. Note that you have to modify the IP address to the remote IP address of the computer running the Mule instance and the port to the port number entered in the configuration earlier. If the Jolokia agent was successfully enabled, you should see something like this in your web browser:
With the Jolokia agent in place, we can now monitor the Mule instance using Hawtio:
- Download the Hawtio JAR from http://hawt.io/getstarted/index.html
- Launch Hawtio using the command “java -jar hawtio-app-1.4.17.jar” (the name of the JAR file needs to match that of the file you downloaded earlier).
- Hawtio should open a web browser and display a welcome page.
If not, try the URL http://localhost:8080/hawtio/welcome
- Click the Connect button in the upper left corner of the Hawtio webpage.
- Click the Remote button.
- On the right, enter the remote IP of the computer on which your Mule instance is running in the Host field. 192.168.1.73 in my case.
- Enter the port, 1095 in my case, from the configuration file in the Port field.
- Make sure the Use proxy checkbox is checked.
- Click the Connect to remote server button.
- A new window or tab should open in your web browser.
- Click the Dashboard button in the upper left corner.
You should now see information about the target computer, such as CPU and memory usage.
- Click the JMX button next to the Dashboard button.
Here you find the regular JMX management features.
Click the Threads button next to the JMX button.
This tab shows information about the different threads running in the target JVM.
There are more things to tweak, but I hope that this will get you started with remote JMX monitoring of a Mule instance. From there you can start modifying the parameters, adding security etc according to your requirements.
More information on Mule JMX Management can be found here: http://www.mulesoft.org/documentation/display/current/JMX+Management
The Oracle webpage on JMX technology can be found here: http://www.oracle.com/technetwork/java/javase/tech/javamanagement-140525.html
Finally, the Oracle JMX tutorial can be found here: http://docs.oracle.com/javase/tutorial/jmx/
Published at DZone with permission of Ivan K . See the original article here.
Opinions expressed by DZone contributors are their own.