Wednesday, February 2, 2011

Enabling JMX monitoring in Servicemix for pax-web jetty instance.

In Servicemix 4.x OSGi HTTP service is provided using pax-web. By default, it doesn't expose MBean for underlying Jetty instance running inside pax-web.

To enable monitoring this jetty instance you need to use fragment bundle that would connect underlying jetty to Servicemix MBeanServer using additional jetty configuration.

Here are steps to do this:

1. Create a OSGi Fragment-Bundle which will attach to pax-web-jetty OSGi service. Bundle Fragment project pom.xml contains following:

<project xmlns=""
<name>OPS4J Pax Web - Configuring Jetty JMX connection</name>

2. This bundle (Fragment) would have additional Jetty configuration xml file jetty.xml which would (reside in src/main/resources folder) look like this:

<configure class="org.mortbay.jetty.Server">
<call id="jettyMBeanServer" class="" name="getPlatformMBeanServer">

<!-- =========================================================== -->
<!-- Initialize the Jetty MBean container -->
<!-- =========================================================== -->
<get id="Container" name="container">
<call name="addEventListener">
<new class="">
<arg><ref id="jettyMBeanServer"></ref>
<call name="start">


3. Once the fragment bundle is built install it in Servicemix instance which is not currently running pax-web OSGi services. (I used Servicemix instance with minimal bundles only config feature was installed) I installed it using osgi:install file:///.... or something like osgi:install mvn:org.ops4j.pax.web/config-jetty-jmx where the groupId for my Fragment bundle project was org.ops4j.pax.web and artifactId config-jetty-jmx.

4. Once this is installed you can install pax-web. I deployed war feature which installs and starts pax-web feature.

5. At this stage your Fragment bundle would get attached to pax-web-jetty Host Bundle and enable JMX monitoring. To confirm this if you run osgi:list you should see something like (Note Fragment and Host entries):

[33] [Resolved ] [ ] [ 60] OPS4J Pax Web - Configuring Jetty JMX connection (1.0.0.SNAPSHOT)
Hosts: 39
[ 34] [Active ] [ ] [ 60] geronimo-servlet_2.5_spec (1.1.2)
[ 35] [Active ] [ ] [ 60] Apache ServiceMix :: Bundles :: jetty (
[ 36] [Active ] [ ] [ 60] OPS4J Pax Web - API (0.7.3)
[ 37] [Active ] [ ] [ 60] OPS4J Pax Web - Service SPI (0.7.3)
[ 38] [Active ] [ ] [ 60] OPS4J Pax Web - Runtime (0.7.3)
[ 39] [Active ] [ ] [ 60] OPS4J Pax Web - Jetty (0.7.3)
Fragments: 33
[ 40] [Active ] [ ] [ 60] OPS4J Pax Web - Jsp Support (0.7.3)
[ 41] [Active ] [ ] [ 60] OPS4J Pax Web - Extender - WAR (0.7.3)
[ 42] [Active ] [ ] [ 60] OPS4J Pax Web - Extender - Whiteboard (0.7.3)
[ 43] [Active ] [ ] [ 60] OPS4J Pax Url - war:, war-i: (1.1.3)
[ 44] [Active ] [Created ] [ 60] Apache Karaf :: WAR Deployer (2.0.0.fuse-02-00)

6. At this stage if you start JConsole and look connect to running Servicemix instance you should be able to see following MBeans appearing in MBeans tab:
a. org.mortbay.jetty.servlet
b. org.mortbay.thread
c. org.ops4j.pax.web.service.jetty.internal

I did see some InstanceAlreadyExists exceptions in Servicemix instance but wasn't able to resolve them quickly so just left there since in my opinion they are harmless.

I hope this helps anyone who wants to configure internal Jetty instance run by pax-web in Servicemix/Karaf.


M@ulEX, Alexandre GUYOT said...


(see my post

I want to create a monitoring interface accessible from the web browser. The chosen solution is the use of WebSockets a good idea because it works perfectly with the jetty WebSockets.

But when I try my war directly into jetty (outside FuseESB, it works perfectly). So I think the package jetty-WebSocket I installed is not working because there is no feature built into the original jetty.

I finally managed to package integrated jetty-WebSocket in the jetty feature. However I still get the same error, how to specify in the jetty's configuration to load at startup WebSockets support! Where is the file in FuseESB (a start.ini like in jetty)?

I think it's something need to enable but I don't know what and where ? Have you got an idea to solve my promblem ?

Thanks a lot !


Mazya uchapati (my low-tech efforts) said...

Hi Maulex,

I don't know answer to your question but will try to find out sooner and comment on this same post.


Ulhas Bhole

M@ulEX, Alexandre GUYOT said...

Thank you for your answer, I continued to look on my side! But this is beyond my area of ​​expertise.

Thanks for your help