blob: 290df4c77b538ae585a0683b60bc8c4e7e0bca4d [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Chapter&nbsp;14.&nbsp;Java Management Extensions (JMX)</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty"><link rel="up" href="jetty-admin-guide.html" title="Part&nbsp;III.&nbsp;Jetty Administration Guide"><link rel="prev" href="using-annotations-embedded.html" title="Using Annotations with Jetty Embedded"><link rel="next" href="jetty-jmx-annotations.html" title="Jetty JMX Annotations"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><link rel="stylesheet" href="css/highlighter/foundation.css"><script src="js/highlight.pack.js"></script><script>
hljs.initHighlightingOnLoad();
</script><link type="text/css" rel="stylesheet" href="css/font-awesome/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small">
Version: 9.3.28.v20191105</span></td><td style="width: 50%"></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&nbsp;14.&nbsp;Java Management Extensions (JMX)</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="using-annotations-embedded.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;III.&nbsp;Jetty Administration Guide<br><a accesskey="p" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="jetty-jmx-annotations.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at
<span class="website">www.webtide.com</span></a></h5><p>
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 for sponsored feature development
</p></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="jmx-chapter"></a>Chapter&nbsp;14.&nbsp;Java Management Extensions (JMX)</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="section"><a href="jmx-chapter.html#using-jmx">Using JMX with Jetty</a></span></dt><dt><span class="section"><a href="jetty-jmx-annotations.html">Jetty JMX Annotations</a></span></dt><dt><span class="section"><a href="jetty-jconsole.html">Managing Jetty with JConsole and JMC</a></span></dt></dl></div><p>The <a class="link" href="http://java.sun.com/products/JavaManagement/" target="_top">Java Management Extensions (JMX) API</a> is a standard API for managing and monitoring resources such as applications, devices, services, and the Java virtual machine.</p><p>Typical uses of the JMX technology include:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">Consulting and changing application configuration</li><li class="listitem">Accumulating and making available statistics about application behavior</li><li class="listitem">Notifying of state changes and erroneous conditions</li></ul></div><p>The JMX API includes remote access, so a remote management program can interact with a running application for these purposes.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="using-jmx"></a>Using JMX with Jetty</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="jmx-chapter.html#configuring-jmx">Configuring JMX</a></span></dt><dt><span class="section"><a href="jmx-chapter.html#enabling-jmxconnectorserver-for-remote-access">Enabling JMXConnectorServer for Remote Access</a></span></dt><dt><span class="section"><a href="jmx-chapter.html#securing-remote-access">Securing Remote Access</a></span></dt><dt><span class="section"><a href="jmx-chapter.html#custom-monitor-applcation">Custom Monitor Application</a></span></dt></dl></div><p>Jetty JMX integration uses the platform MBean server implementation that Java VM provides.
The integration is based on the <code class="literal">ObjectMBean</code> implementation of <code class="literal">DynamicMBean</code>.
This implementation allows you to wrap an arbitrary POJO in an MBean and annotate it appropriately to expose it via JMX.
See <a class="xref" href="jetty-jmx-annotations.html" title="Jetty JMX Annotations">Jetty JMX Annotations</a>.</p><p>The <code class="literal">MBeanContainer</code> implementation of the <code class="literal">Container.Listener</code> interface coordinates creation of MBeans.
The Jetty Server and it&#8217;s components use a <a class="link" href="http://www.eclipse.org/jetty/javadoc/9.3.28.v20191105/org/eclipse/jetty/util/component/Container.html" target="_top">Container</a> to maintain a containment tree of components and to support notification of changes to that tree.
The <code class="literal">MBeanContainer</code> class listens for Container events and creates and destroys MBeans as required to wrap all Jetty components.</p><p>You can access the MBeans that Jetty publishes both through built-in Java VM connector via JConsole or JMC, or by registering a remote JMX connector and using a remote JMX agent to monitor Jetty.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="configuring-jmx"></a>Configuring JMX</h3></div></div></div><p>This guide describes how to initialize and configure the Jetty JMX integration.</p><p>To monitor an application using JMX, perform the following steps:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">Configure the application to instantiate an MBean container.</li><li class="listitem">Instrument objects to be MBeans.</li><li class="listitem">Provide access for JMX agents to MBeans.</li></ul></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="accessing-jetty-mbeans"></a>Using JConsole to Access Jetty MBeans</h4></div></div></div><p>The simplest way to access the MBeans that Jetty publishes is to use the <a class="link" href="http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html" target="_top">JConsole utility</a> the Java Virtual Machine supplies.
See <a class="xref" href="jetty-jconsole.html" title="Managing Jetty with JConsole and JMC">Managing Jetty with JConsole and JMC</a> for instructions on how to configure JVM for use with JConsole or JMC.</p><p>To access Jetty MBeans via JConsole or JMC, you must:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">Enable the registration of Jetty MBeans into the platform MBeanServer.</li><li class="listitem">Enable a <code class="literal">JMXConnectorServer</code> so that JConsole/JMC can connect and visualize the MBeans.</li></ul></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="registering-jetty-mbeans"></a>Registering Jetty MBeans</h4></div></div></div><p>Configuring Jetty JMX integration differs for standalone and embedded Jetty.</p><div class="section"><div class="titlepage"><div><div><h5 class="title"><a name="jmx-standalone-jetty"></a>Standalone Jetty</h5></div></div></div><p>JMX is not enabled by default in the Jetty distribution.
To enable JMX in the Jetty distribution, run the following, where <code class="literal">{$jetty.home}</code> is the directory where you have the Jetty distribution located (see <a class="link" href="startup-base-and-home.html" title="Managing Jetty Base and Jetty Home">the documentation for Jetty base vs. home examples</a>):</p><div class="screenexample"><pre class="screen">$ java -jar {$jetty.home}/start.jar --add-to-start=jmx</pre></div><p>Running the above command will append the available configurable elements of the JMX module to the <code class="literal">{$jetty.base}/start.ini</code> file.
If you are managing separate ini files for your modules in the distribution, use <code class="literal">--add-to-start.d=jmx</code> instead.</p><p>If you wish to add remote access for JMX, you will also need to enable the JMX-Remote module:</p><div class="screenexample"><pre class="screen">$ java -jar {$jetty.home}/start.jar --add-to-start=jmx-remote</pre></div></div><div class="section"><div class="titlepage"><div><div><h5 class="title"><a name="jmx-embedded-jetty"></a>Embedded Jetty</h5></div></div></div><p>When running Jetty embedded into an application, create and configure an MBeanContainer instance as follows:</p><pre xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><code>Server server = new Server();
// Setup JMX
MBeanContainer mbContainer=new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
server.addEventListener(mbContainer);
server.addBean(mbContainer);
// Add loggers MBean to server (will be picked up by MBeanContainer above)
server.addBean(Log.getLog());</code></pre><p>Notice that Jetty creates the <code class="literal">MBeanContainer</code> immediately after creating the Server, and immediately after registering it as an <code class="literal">EventListener</code> of the Server object (which is also a Container object).</p><p>Because logging is initialized prior to the <code class="literal">MBeanContainer</code> (even before the Server itself), it is necessary to register the logger manually via <code class="literal">server.addBean()</code> so that the loggers may show up in the JMX tree.</p></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="jmx-using-jetty-maven-plugin"></a>Using the Jetty Maven Plugin with JMX</h4></div></div></div><p>If you are using the <a class="link" href="jetty-maven-plugin.html" title="Configuring the Jetty Maven Plugin">Jetty Maven plugin</a> you should copy the <code class="literal">/etc/jetty-jmx.xml</code> file into your webapp project somewhere, such as <code class="literal">/src/etc,</code> then add a <code class="literal">&lt;jettyconfig&gt;</code> element to the plugin <code class="literal">&lt;configuration&gt;</code>:</p><pre xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><code>&lt;plugin&gt;
&lt;groupid&gt;org.eclipse.jetty&lt;/groupid&gt;
&lt;artifactid&gt;jetty-maven-plugin&lt;/artifactid&gt;
&lt;version&gt;9.3.28.v20191105&lt;/version&gt;
&lt;configuration&gt;
&lt;scanintervalseconds&gt;10&lt;/scanintervalseconds&gt;
&lt;jettyXml&gt;src/etc/jetty-jmx.xml&lt;/jettyXml&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;</code></pre></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="enabling-jmxconnectorserver-for-remote-access"></a>Enabling JMXConnectorServer for Remote Access</h3></div></div></div><p>There are two ways of enabling remote connectivity so that JConsole or JMC can connect to visualize MBeans.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">Use the <code class="literal">com.sun.management.jmxremote</code> system property on the command line.
Unfortunately, this solution does not work well with firewalls and is not flexible.</li><li class="listitem">Use Jetty&#8217;s <code class="literal">ConnectorServer</code> class.
To enable use of this class, uncomment the correspondent portion in <code class="literal">/etc/jetty-jmx.xml,</code> like this:</li></ul></div><pre xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><code>&lt;New id="ConnectorServer" class="org.eclipse.jetty.jmx.ConnectorServer"&gt;
&lt;Arg&gt;
&lt;New class="javax.management.remote.JMXServiceURL"&gt;
&lt;Arg type="java.lang.String"&gt;rmi&lt;/Arg&gt;
&lt;Arg type="java.lang.String" /&gt;
&lt;Arg type="java.lang.Integer"&gt;&lt;SystemProperty name="jetty.jmxrmiport" default="1099"/&gt;&lt;/Arg&gt;
&lt;Arg type="java.lang.String"&gt;/jndi/rmi://&lt;SystemProperty name="jetty.jmxrmihost" default="localhost"/&gt;:&lt;SystemProperty name="jetty.jmxrmiport" default="1099"/&gt;/jmxrmi&lt;/Arg&gt;
&lt;/New&gt;
&lt;/Arg&gt;
&lt;Arg&gt;org.eclipse.jetty.jmx:name=rmiconnectorserver&lt;/Arg&gt;
&lt;Call name="start" /&gt;
&lt;/New&gt;</code></pre><p>This configuration snippet starts an <code class="literal">RMIRegistry</code> and a <code class="literal">JMXConnectorServer</code> both on port 1099 (by default), so that firewalls should open just that one port to allow connections from JConsole or JMC.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="securing-remote-access"></a>Securing Remote Access</h3></div></div></div><p><code class="literal">JMXConnectorServer</code> several options to restrict access.
For a complete guide to controlling authentication and authorization in JMX, see <a class="link" href="https://blogs.oracle.com/lmalventosa/entry/jmx_authentication_authorization" target="_top">Authentication and Authorization in JMX RMI connectors</a> in Luis-Miguel Alventosa&#8217;s blog.</p><p>To restrict access to the <code class="literal">JMXConnectorServer</code>, you can use this configuration, where the <code class="literal">jmx.password</code> and <code class="literal">jmx.access</code> files have the format specified in the blog entry above:</p><pre xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><code>&lt;New id="ConnectorServer" class="org.eclipse.jetty.jmx.ConnectorServer"&gt;
&lt;Arg&gt;
&lt;New class="javax.management.remote.JMXServiceURL"&gt;
&lt;Arg type="java.lang.String"&gt;rmi&lt;/Arg&gt;
&lt;Arg type="java.lang.String" /&gt;
&lt;Arg type="java.lang.Integer"&gt;&lt;SystemProperty name="jetty.jmxrmiport" default="1099"/&gt;&lt;/Arg&gt;
&lt;Arg type="java.lang.String"&gt;/jndi/rmi://&lt;SystemProperty name="jetty.jmxrmihost" default="localhost"/&gt;:&lt;SystemProperty name="jetty.jmxrmiport" default="1099"/&gt;/jmxrmi&lt;/Arg&gt;
&lt;/New&gt;
&lt;/Arg&gt;
&lt;Arg&gt;
&lt;Map&gt;
&lt;Entry&gt;
&lt;Item&gt;jmx.remote.x.password.file&lt;/Item&gt;
&lt;Item&gt;
&lt;New class="java.lang.String"&gt;&lt;Arg&gt;&lt;Property name="jetty.home" default="." /&gt;/resources/jmx.password&lt;/Arg&gt;&lt;/New&gt;
&lt;/Item&gt;
&lt;/Entry&gt;
&lt;Entry&gt;
&lt;Item&gt;jmx.remote.x.access.file&lt;/Item&gt;
&lt;Item&gt;
&lt;New class="java.lang.String"&gt;&lt;Arg&gt;&lt;Property name="jetty.home" default="." /&gt;/resources/jmx.access&lt;/Arg&gt;&lt;/New&gt;
&lt;/Item&gt;
&lt;/Entry&gt;
&lt;/Map&gt;
&lt;/Arg&gt;
&lt;Arg&gt;org.eclipse.jetty.jmx:name=rmiconnectorserver&lt;/Arg&gt;
&lt;Call name="start" /&gt;
&lt;/New&gt;</code></pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="custom-monitor-applcation"></a>Custom Monitor Application</h3></div></div></div><p>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 the <code class="literal">/etc/jetty-jmx.xml</code> configuration file and optionally modify the endpoint name.
Doing so creates a JMX HTTP connector and registers a JMX URL that outputs to the <code class="literal">Stderr</code> log.</p><p>You should provide the URL that appears in the log to your monitor application in order to create an <code class="literal">MBeanServerConnection.</code>
You can use the same URL to connect to your Jetty instance from a remote machine using JConsole or JMC.
See the <a class="link" href="https://github.com/eclipse/jetty.project/tree/jetty-9.3.x/jetty-jmx/src/main/config/etc/jetty-jmx.xml" target="_top">configuration file</a> for more details.</p></div></div></div><script type="text/javascript">
SyntaxHighlighter.all()
</script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="using-annotations-embedded.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="jetty-admin-guide.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="jetty-jmx-annotations.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Using Annotations with Jetty Embedded&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></td><td width="40%" align="right" valign="top">&nbsp;Jetty JMX Annotations</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout">
See an error or something missing?
<span class="callout"><a href="http://github.com/eclipse/jetty.project">Contribute to this documentation at
<span class="website"><i class="fa fa-github" aria-hidden="true"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2019-11-05)</i></span></div></p></body></html>