Jetty/Tutorial/JMX

From Eclipsepedia

< Jetty‎ | Tutorial
Revision as of 20:35, 22 December 2009 by Michael.webtide.com (Talk | contribs)

Jump to: navigation, search



Contents

Introduction

Jetty JMX integration is based on the ObjectMBean implementation of DynamicMBean. This implementation allows an arbitrary POJO to be wrapped in an MBean and for meta data to be provided by properties files

The creation of MBeans is coordinated by the MBeanContainer implementation of the Container.Listener interface. The Jetty Server and it's components use a Container to maintain a containment tree of components and to support notification of changes to that tree. The MBeanContainer class listens for Container events and creates and destroys MBeans as required to wrap all Jetty components.

Details

The simplest way to access the MBeans that are published by Jetty is to use the JConsole utility supplied with Sun's Java Virtual Machine. The steps required to configure Jetty JMX integration will be different depending on the way that Jetty is bootstrapped.

Jetty Standalone

When running in standalone mode, the MBeanContainer instance can be configured for a Jetty server by the jetty-jmx.xml configuration file. This can be run with the standard configuration file as follows:

java -jar start.jar OPTIONS=Server,jmx etc/jetty-jmx.xml etc/jetty.xml

Please make sure that the jetty-jmx.xml is the first XML file listed in the command line to ensure that all instances of objects that supposed to be registered as MBeans are detected properly.

Embedded Jetty

If Jetty is embedded into an application, the following snippet of code shows how to create and configure an MBeanContainer instance:

Server _server = new Server();
 
// Setup JMX
MBeanContainer mbContainer=new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
_server.getContainer().addEventListener(mbContainer);
_server.addBean(mbContainer);
mbContainer.addBean(Log.getLog());

Please note that MBeanContainer is created immediately after the Server is created, and that an MBean is created for it immediately after it is registered as an EventListener of the Server's Container object. Because logging is initialized prior to MBeanContainer, it is necessary to create an MBean for the logger manually as well.

Jetty Maven Plugin

If you are using the Jetty Maven plugin you should copy the etc/jetty-jmx.xml file into your webapp project somewhere, such as src/etc, then add a <jettyconfig> element to the plugin <configuration>:

<plugin>
  <groupid>org.mortbay.jetty</groupid>
  <artifactid>maven-jetty-plugin</artifactid>
  <version>${project.version}</version>
  <configuration>
    <scanintervalseconds>10</scanintervalseconds>
    <jettyconfig>src/etc/jetty-jmx.xml</jettyconfig>
  </configuration>
</plugin>

Custom Monitor Application

You can also write a custom application using JMX API that will monitor your Jetty server. In order for this application to be able to connect to your Jetty server, you will need to un-comment the last section of etc/jetty-jmx.xml configuration file. That will create a JMX HTTP connector and register a JMX URL that it will output to the Stderr log that in turn you should provide to your monitor appplication. See the configuration file for more details.

Additional Resources

See Run Jetty with JConsole for instructions on how to configure JVM for use with JConsole.

You can also use java-monitor to monitor your Jetty server using JMX. See Jetty java-monitor feature guide for more information.