private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
This page contains content that we have migrated from Jetty 7 or Jetty 8 documentation into the correct format, but we have not yet audited it for technical accuracy in with Jetty 9. Be aware that examples or information contained on this page may be incorrect. Please check back soon as we continue improving the documentation, or submit corrections yourself to this page through Github. Thank you.
Table of Contents
The Java Management Extensions (JMX) API is a standard API for managing and monitoring resources such as applications, devices, services, and the Java virtual machine.
Typical uses of the JMX technology include:
Consulting and changing application configuration.
Accumulating and making available statistics about application behavior.
Notifying of state changes and erroneous conditions.
The JMX API includes remote access, so a remote management program can interact with a running application for these purposes.
Jetty JMX integration uses the platform MBean server implementation that Java VM provides. The integration is based on the ObjectMBean implementation of DynamicMBean. This implementation allows you to wrap an arbitrary POJO in an MBean and for [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-jmx/src/main/resources/org/eclipse/jetty/?root=RT_Jetty properties files]. to provide metadata.
TheMBeanContainer immplementation of the Container.Listener inteface coordinates creation of MBeans. The Jetty Server and it's components use a [http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/util/component/Container.html 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.
You can access the MBeans that Jetty publishes both through built-in Java VM connector via JConsole, or by registering a remote JMX connector and using a remote JMX agent to monitor Jetty.
This guide describes how to initialize and configure the Jetty JMX integration.
To monitor an application using JMX, perform the following steps:
Configure the application to instantiate an MBean container.
Instrument objects to be MBeans.
Provide access for JMX agents to MBeans.
The simplest way to access the MBeans that Jetty publishes is to use the JConsole utility the Java Virtual Machine supplies. See [[Jetty/Howto/Run Jetty_with_JConsole|Run Jetty with JConsole]] for instructions on how to configure JVM for use with JConsole.
To access Jetty MBeans via JConsole, you must:
Enable the registration of Jetty MBeans into the platform MBeanServer.
Enable a JMXConnectorServer so that JConsole can connect and visualize the MBeans.
Configuring Jetty JMX integration differs for standalone and embedded Jetty.
When running in standalone mode, you can use the
jetty-jmx.xml
configuration file to configure the
MBeanContainer instance for a Jetty server. You can run this with the
standard configuration file as follows:
java -jar start.jar OPTIONS=Server,jmx etc/jetty-jmx.xml etc/jetty.xml
Make sure that the jetty-jmx.xml
is the
first XML file listed in the command line to
ensure that Jetty properly detects all instances of objects that
should be registered as MBeans.
When running Jetty embedded into an application, create and configure an MBeanContainer instance as follows:
Server _server = new Server(); // Setup JMX MBeanContainer mbContainer=new MBeanContainer(ManagementFactory.getPlatformMBeanServer()); _server.getContainer().addEventListener(mbContainer); _server.addBean(mbContainer); // Register loggers as MBeans mbContainer.addBean(Log.getLog());
Notice that Jetty creates the MBeanContainer immediately after creating the Server, and immediately after registering it as an EventListener of the Server's Container object.
Because logging is initialized prior to the MBeanContainer, it
is necessary to register the logger manually via
MBeanContainer.addBean().
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>9.0.2-SNAPSHOT</version> <configuration> <scanintervalseconds>10</scanintervalseconds> <jettyXml>src/etc/jetty-jmx.xml</jettyXml> </configuration> </plugin>
There are two ways of enabling remote connectivity so that JConsole can connect to visualize MBeans.
Use the com.sun.management.jmxremote
system
property on the command line. Unfortunately, this solution does not
play well with firewalls and it is not flexible.
Use Jetty's ConnectorServer
class. To enable use
of this class, uncomment the correspondent portion in
etc/jetty-jmx.xml,
like this:
<New id="ConnectorServer" class="org.eclipse.jetty.jmx.ConnectorServer"> <Arg> <New class="javax.management.remote.JMXServiceURL"> <Arg type="java.lang.String">rmi</Arg> <Arg type="java.lang.String" /> <Arg type="java.lang.Integer"><SystemProperty name="jetty.jmxrmiport" default="1099"/></Arg> <Arg type="java.lang.String">/jndi/rmi://<SystemProperty name="jetty.jmxrmihost" default="localhost"/>:<SystemProperty name="jetty.jmxrmiport" default="1099"/>/jmxrmi</Arg> </New> </Arg> <Arg>org.eclipse.jetty.jmx:name=rmiconnectorserver</Arg> <Call name="start" /> </New>
This configuration snippet starts an RMIRegistry and a JMXConnectorServer both on port 1099 (by default), so that firewalls should open just that one port to allow connections from JConsole.
JMXConnectorServer several options to restrict access. For a complete guide to controlling authentication and authorization in JMX, see Authentication and Authorization in JMX RMI connectors in Luis-Miguel Alventosa's blog.
To restrict access to the JMXConnectorServer, you can use this
configuration, where the jmx.password
and
jmx.access
files have the format specified in the
blog entry above:
<New id="ConnectorServer" class="org.eclipse.jetty.jmx.ConnectorServer"> <Arg> <New class="javax.management.remote.JMXServiceURL"> <Arg type="java.lang.String">rmi</Arg> <Arg type="java.lang.String" /> <Arg type="java.lang.Integer"><SystemProperty name="jetty.jmxrmiport" default="1099"/></Arg> <Arg type="java.lang.String">/jndi/rmi://<SystemProperty name="jetty.jmxrmihost" default="localhost"/>:<SystemProperty name="jetty.jmxrmiport" default="1099"/>/jmxrmi</Arg> </New> </Arg> <Arg> <Map> <Entry> <Item>jmx.remote.x.password.file</Item> <Item> <New class="java.lang.String"><Arg><Property name="jetty.home" default="." />/resources/jmx.password</Arg></New> </Item> </Entry> <Entry> <Item>jmx.remote.x.access.file</Item> <Item> <New class="java.lang.String"><Arg><Property name="jetty.home" default="." />/resources/jmx.access</Arg></New> </Item> </Entry> </Map> </Arg> <Arg>org.eclipse.jetty.jmx:name=rmiconnectorserver</Arg> <Call name="start" /> </New>
Using the JMX API, you can also write a custom application to
monitor your Jetty server. To allow this application to connect to your
Jetty server, you need to uncomment the last section of your
etc/jetty-jmx.xml
configuration file and optionally modify
the endpoint name. Doing so creates a JMX HTTP connector and registers a
JMX URL that outputs to the Stderr
log.
You should provide the URL that appears in the log to your monitor
application in order to create an MBeanServerConnection.
You can use the same URL to connect to your Jetty instance from a remote
machine using JConsole. See the configuration
file for more details.
See an error or something missing? Contribute to this documentation at Github!