camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Camel JMX
Date Thu, 08 Oct 2009 09:23:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/Camel+JMX">Camel
JMX</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h2><a name="CamelJMX-CamelJMX"></a>Camel JMX</h2>

<p>Apache Camel has extensive support for JMX to allow you to monitor and control the
Camel managed objects a JMX client.</p>

<div>
<ul>
    <li><a href='#CamelJMX-CamelJMX'>Camel JMX</a></li>
<ul>
    <li><a href='#CamelJMX-SpringDependency'>Spring Dependency</a></li>
    <li><a href='#CamelJMX-UsingJMXtomanageApacheCamel'>Using JMX to manage Apache
Camel</a></li>
    <li><a href='#CamelJMX-DisablingJMXinstrumentationagentinCamel'>Disabling
JMX instrumentation agent in Camel</a></li>
    <li><a href='#CamelJMX-LocatingaMBeanServerintheJavaVM'>Locating a MBeanServer
in the Java VM</a></li>
    <li><a href='#CamelJMX-CreatingJMXRMIConnectorServer'>Creating JMX RMI Connector
Server</a></li>
    <li><a href='#CamelJMX-JMXServiceURL'>JMX Service URL</a></li>
    <li><a href='#CamelJMX-UsingJConsoletomonitorCamel'>Using JConsole to monitor
Camel</a></li>
    <li><a href='#CamelJMX-TheSystemPropertiesforCamelJMXsupport'>The SystemProperties
for Camel JMX support</a></li>
    <li><a href='#CamelJMX-JMXinsideanApplicationServer'>JMX inside an Application
Server</a></li>
<ul>
    <li><a href='#CamelJMX-JBossAS4'>JBoss AS 4</a></li>
    <li><a href='#CamelJMX-WebSphere'>WebSphere</a></li>
</ul>
    <li><a href='#CamelJMX-AdvancedJMXConfiguration'>Advanced JMX Configuration</a></li>
<ul>
    <li><a href='#CamelJMX-Example%3A'>Example:</a></li>
    <li><a href='#CamelJMX-jmxAgentPropertiesReference'>jmxAgent Properties Reference</a></li>
</ul>
    <li><a href='#CamelJMX-RegisteringyourownManagedEndpoints'>Registering your
own Managed Endpoints</a></li>
    <li><a href='#CamelJMX-ProgrammingyourownManagedServices'>Programming your
own Managed Services</a></li>
    <li><a href='#CamelJMX-ManagementNamingStrategy'>ManagementNamingStrategy</a></li>
    <li><a href='#CamelJMX-ManagementStrategy'>ManagementStrategy</a></li>
    <li><a href='#CamelJMX-Configuringlevelofgranularityforperformancestatistics'>Configuring
level of granularity for performance statistics</a></li>
    <li><a href='#CamelJMX-Whichendpointsareregistered'>Which endpoints are registered</a></li>
    <li><a href='#CamelJMX-Whichprocessorsareregistered'>Which processors are
registered</a></li>
    <li><a href='#CamelJMX-SeeAlso'>See Also</a></li>
</ul>
</ul></div>

<h3><a name="CamelJMX-SpringDependency"></a>Spring Dependency</h3>
<p><b>spring-context.jar</b> is needed on the classpath by Camel to be able
to use JMX instrumentation. If this .jar is <b>not</b> on the classpath Camel
will fallback to non JMX mode. This situation is logged at <tt>WARN</tt> level
using logger name <tt>org.apache.camel.impl.DefaultCamelContext</tt>.</p>

<h3><a name="CamelJMX-UsingJMXtomanageApacheCamel"></a>Using JMX to manage
Apache Camel</h3>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Some platforms
do not allow access to its platform mbean server</b><br /><p>The Oracle
OC4J J2EE application server will not allow Camel to access the platform mbean server. You
can identify this in the log as Camel will log a WARNING.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
xxx xx, xxxx xx:xx:xx xx org.apache.camel.management.InstrumentationLifecycleStrategy onContextStart
WARNING: Could not register CamelContext MBean
java.lang.SecurityException: Unauthorized access from application: xx to MBean: java.lang:type=ClassLoading
        at oracle.oc4j.admin.jmx.shared.UserMBeanServer.checkRegisterAccess(UserMBeanServer.java:873)
</pre>
</div></div>
<p>To resolve this you should disable the JMX agent in Camel, see section <em>Disabling
JMX instrumentation agent in Camel</em></p></td></tr></table></div>

<p>By default, JMX instrumentation agent is enabled in Camel which means that Camel
runtime creates and registers MBean management objects with a MBeanServer instance in the
VM. This allows Camel users instantly obtain insights into how Camel routes perform down to
the individual processor's level.</p>

<p>The supported types of management objects are <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/management/ManagedEndpoint.html"
rel="nofollow">endpoint </a>, <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/management/ManagedRoute.html"
rel="nofollow">route</a>, <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/management/ManagedService.html"
rel="nofollow">service</a>, and <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/management/PerformanceCounter.html"
rel="nofollow">processor</a>. Some of these management objects also expose lifecycle
operations in addition to performance counter attributes.</p>

<p>The <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/management/DefaultManagementNamingStrategy.html"
rel="nofollow">DefaultManagementNamingStrategy</a> is the default naming strategy
which builds object names used for MBean registration. By default, <b>org.apache.camel</b>
is the domain name for all object names created by CamelNamingStrategy. The domain name of
the MBean object can be configured by Java VM system property:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
-Dorg.apache.camel.jmx.mbeanObjectDomainName=your.domain.name
</pre>
</div></div>
<p>Or, by adding a <b>jmxAgent</b> element inside the camelContext element
in Spring configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span
class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>&gt;
</span>  &lt;jmxAgent id=<span class="code-quote">"agent"</span> mbeanObjectDomainName=<span
class="code-quote">"your.domain.name"</span>/&gt;
    ...
&lt;/camelContext&gt;
</pre>
</div></div>
<p>Spring configuration always takes precedence over system properties when they both
present. It is true for all of JMX related configurations.</p>

<h3><a name="CamelJMX-DisablingJMXinstrumentationagentinCamel"></a>Disabling
JMX instrumentation agent in Camel</h3>

<p>You can disable JMX instrumentation agent by setting Java VM system property as follow.
The property value is treated as boolean.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
-Dorg.apache.camel.jmx.disabled=True
</pre>
</div></div>
<p>Or, by adding a <b>jmxAgent</b> element inside the camelContext element
in Spring configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span
class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>&gt;
</span>  &lt;jmxAgent id=<span class="code-quote">"agent"</span> disabled=<span
class="code-quote">"<span class="code-keyword">true</span>"</span>/&gt;
    ...
&lt;/camelContext&gt;
</pre>
</div></div>

<p>Or in Camel 2.1 its a bit easier (not having to use JVM system property) if using
pure Java as you can disable it as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
CamelContext camel = <span class="code-keyword">new</span> DefaultCamelContext();
camel.disableJMX();
</pre>
</div></div>

<h3><a name="CamelJMX-LocatingaMBeanServerintheJavaVM"></a>Locating a MBeanServer
in the Java VM</h3>

<p>Each CamelContext can have an instance of <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/spi/InstrumentationAgent.html"
rel="nofollow">InstrumentationAgent</a> wrapped insider the <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/management/InstrumentationLifecycleStrategy.html"
rel="nofollow">InstrumentationLifecycleStrategy</a>. The InstrumentationAgent is
the object that interfaces with a <a href="http://java.sun.com/j2se/1.5.0/docs/api/javax/management/MBeanServer.html"
rel="nofollow">MBeanServer</a> to register/unregister Camel MBeans. Multiple CamelContexts/InstrumentationAgents
can/should share a MBeanServer. By default, Camel runtime picks the first MBeanServer returned
by <a href="http://java.sun.com/j2se/1.5.0/docs/api/javax/management/MBeanServerFactory.html#findMBeanServer(java.lang.String)"
rel="nofollow">MBeanServerFactory.findMBeanServer method</a> that matches the default
domain name of <b>org.apache.camel</b>.&nbsp; You may want to change the default
domain name to match the MBeanServer instance that you are already using in your application.&nbsp;
Especially, if your MBeanServer is attached to a JMX connector server, you will not need to
create a connector server in Camel.</p>

<p>You can configure the matching default domain name via system property.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
-Dorg.apache.camel.jmx.mbeanServerDefaultDomain=&lt;your.domain.name&gt;
</pre>
</div></div>
<p>Or, by adding a <b>jmxAgent</b> element inside the camelContext element
in Spring configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span
class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>&gt;
</span>  &lt;jmxAgent id=<span class="code-quote">"agent"</span> mbeanServerDefaultDomain=<span
class="code-quote">"your.domain.name"</span>/&gt;
    ...
&lt;/camelContext&gt;
</pre>
</div></div>
<p>If no matching MBeanServer can be found, a new one is created and the new MBeanServer's
default domain name is set according to the default and configuration as mentioned above.</p>

<p>It is also possible to use the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/ManagementFactory.html#getPlatformMBeanServer()"
rel="nofollow">PlatformMBeanServer</a> when it is desirable to manage JVM MBeans&nbsp;by
setting the system property.&nbsp; The MBeanServer default domain name configuration is
ignored as it is not applicable.&nbsp; <b>Starting in next release (1.5), the default
value of usePlatformMBeanServer will be changed to "True".&nbsp; You can set the property
to "False" to disable using platform MBean server.</b></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
-Dorg.apache.camel.jmx.usePlatformMBeanServer=True
</pre>
</div></div>
<p>Or, by adding a <b>jmxAgent</b> element inside the camelContext element
in Spring configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span
class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>&gt;
</span>  &lt;jmxAgent id=<span class="code-quote">"agent"</span> usePlatformMBeanServer=<span
class="code-quote">"<span class="code-keyword">true</span>"</span>/&gt;
    ...
&lt;/camelContext&gt;
</pre>
</div></div>

<h3><a name="CamelJMX-CreatingJMXRMIConnectorServer"></a>Creating JMX RMI
Connector Server</h3>

<p>JMX connector server enables MBeans to be remotely managed by a JMX client such as
JConsole.&nbsp; Camel JMX RMI connector server can be optionally turned on by setting
system property and the MBeanServer used by Camel is attached to that connector server.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
-Dorg.apache.camel.jmx.createRmiConnector=True
</pre>
</div></div>
<p>Or, by adding a <b>jmxAgent</b> element inside the camelContext element
in Spring configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span
class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>&gt;
</span>  &lt;jmxAgent id=<span class="code-quote">"agent"</span> createConnector=<span
class="code-quote">"<span class="code-keyword">true</span>"</span>/&gt;
    ...
&lt;/camelContext&gt;
</pre>
</div></div>

<h3><a name="CamelJMX-JMXServiceURL"></a>JMX Service URL</h3>

<p>The default JMX Service URL has the format:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
service:jmx:rmi:<span class="code-comment">///jndi/rmi://localhost:&lt;registryPort&gt;/&lt;serviceUrlPath&gt;</span>
</pre>
</div></div>
<p><em>registryPort</em> is the RMI registry port and the default value
is <b>1099</b>.</p>

<p>You can set the RMI registry port by system property.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
-Dorg.apache.camel.jmx.rmiConnector.registryPort=&lt;port number&gt;
</pre>
</div></div>
<p>Or, by adding a <b>jmxAgent</b> element inside the camelContext element
in Spring configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span
class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>&gt;
</span>  &lt;jmxAgent id=<span class="code-quote">"agent"</span> createConnector=<span
class="code-quote">"<span class="code-keyword">true</span>"</span> registryPort=<span
class="code-quote">"port number"</span>/&gt;
    ...
&lt;/camelContext&gt;
</pre>
</div></div>
<p><em>serviceUrlPath</em> is the path name in the URL and the default value
is <b>/jmxrmi/camel</b>.</p>

<p>You can set the service URL path by system property.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
-Dorg.apache.camel.jmx.serviceUrlPath=&lt;path&gt;
</pre>
</div></div>
<p>Or, by adding a <b>jmxAgent</b> element inside the camelContext element
in Spring configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span
class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>&gt;
</span>  &lt;jmxAgent id=<span class="code-quote">"agent"</span> createConnector=<span
class="code-quote">"<span class="code-keyword">true</span>"</span> serviceUrlPath=<span
class="code-quote">"path"</span>/&gt;
    ...
&lt;/camelContext&gt;
</pre>
</div></div>
<p>By default, RMI server object listens on a dynamically generated port which can be
a problem for connection established through a firewall. In such situation, RMI connection
port can be explicitly set by the system property.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
-Dorg.apache.camel.jmx.rmiConnector.connectorPort=&lt;port number&gt;
</pre>
</div></div>
<p>Or, by adding a <b>jmxAgent</b> element inside the camelContext element
in Spring configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span
class="code-quote">"http:<span class="code-comment">//activemq.apache.org/camel/schema/spring"</span>&gt;
</span>  &lt;jmxAgent id=<span class="code-quote">"agent"</span> createConnector=<span
class="code-quote">"<span class="code-keyword">true</span>"</span> connectorPort=<span
class="code-quote">"port number"</span>/&gt;
    ...
&lt;/camelContext&gt;
</pre>
</div></div>
<p>When the connector port option is set, the JMX service URL will become:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
service:jmx:rmi:<span class="code-comment">//localhost:&lt;connectorPort&gt;/jndi/rmi://localhost:&lt;registryPort&gt;/&lt;serviceUrlPath&gt;</span>
</pre>
</div></div>

<h3><a name="CamelJMX-UsingJConsoletomonitorCamel"></a>Using JConsole to
monitor Camel</h3>

<p>The CamelContext should appear in the list of local connections, if you are running
JConsole on the same host as Camel.</p>

<p>To connect to a remote Camel instance, or if the local process does not show up,
use Remote Process option, and enter an URL. Here is an example localhost URL:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
service:jmx:rmi:<span class="code-comment">///jndi/rmi://localhost:1099/jmxrmi/camel</span>
</pre>
</div></div>
<p>Using the Apache Camel which Jconsole<br/>
<a class="confluence-thumbnail-link 910x679" href='http://cwiki.apache.org/confluence/download/attachments/85697/camel-jmx.png'><img
src="/confluence/download/thumbnails/85697/camel-jmx.png" align="absmiddle" border="0" title="updated
version after fix for camel-865" /></a><br/>
&nbsp;</p>

<h3><a name="CamelJMX-TheSystemPropertiesforCamelJMXsupport"></a>The SystemProperties
for Camel JMX support</h3>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property Name </th>
<th class='confluenceTh'> value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> org.apache.camel.jmx </td>
<td class='confluenceTd'> true or false </td>
<td class='confluenceTd'> if is true , it will enable jmx feature in Camel </td>
</tr>
</tbody></table>

<p>See more system properties in this section below: <em>jmxAgent Properties Reference</em></p>

<h3><a name="CamelJMX-JMXinsideanApplicationServer"></a>JMX inside an Application
Server</h3>

<h4><a name="CamelJMX-JBossAS4"></a>JBoss AS 4</h4>

<p>By default JBoss creates its own MBean server.  To allow Camel to expose to the same
server follow these steps:</p>

<p>1. Tell Camel to use the Platform MBean Server (This defaults to true in Camel 1.5)</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camel:camelContext id=<span class="code-quote">"camelContext"</span>&gt;
  &lt;camel:jmxAgent id=<span class="code-quote">"jmxAgent"</span> mbeanObjectDomainName=<span
class="code-quote">"org.yourname"</span> usePlatformMBeanServer=<span class="code-quote">"<span
class="code-keyword">true</span>"</span>  /&gt;
&lt;/camel:camelContext&gt;
</pre>
</div></div>

<p>2. Alter your JBoss instance to use the Platform MBean server.<br/>
Add the following property to your JAVA_OPTS by editing run.sh or run.conf {{ -Djboss.platform.mbeanserver
}} See <a href="http://wiki.jboss.org/wiki/JBossMBeansInJConsole" rel="nofollow">http://wiki.jboss.org/wiki/JBossMBeansInJConsole</a></p>

<h4><a name="CamelJMX-WebSphere"></a>WebSphere</h4>

<p>Alter the mbeanServerDefaultDomain to be "WebSphere"</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camel:jmxAgent id=<span class="code-quote">"agent"</span> createConnector=<span
class="code-quote">"<span class="code-keyword">true</span>"</span> mbeanObjectDomainName=<span
class="code-quote">"org.yourname"</span> mbeanServerDefaultDomain=<span class="code-quote">"WebSphere"</span>/&gt;
</pre>
</div></div>


<h3><a name="CamelJMX-AdvancedJMXConfiguration"></a>Advanced JMX Configuration</h3>

<p>The spring configuration file allows you to configure how Camel is exposed to JMX
for management. In some cases, you could specify more information here, like the connector's
port or the path name.</p>

<h4><a name="CamelJMX-Example%3A"></a>Example:</h4>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span
class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>&gt;
</span>  &lt;jmxAgent id=<span class="code-quote">"agent"</span> createConnector=<span
class="code-quote">"<span class="code-keyword">true</span>"</span> registryPort=<span
class="code-quote">"2000"</span> mbeanServerDefaultDomain=<span class="code-quote">"org.apache.camel.test"</span>/&gt;
    &lt;route&gt;
      &lt;from uri=<span class="code-quote">"seda:start"</span>/&gt;
      &lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;
    &lt;/route&gt;
&lt;/camelContext&gt;
</pre>
</div></div>
<p>If you wish to change the Java 5 JMX settings you can use various <a href="http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html#properties"
rel="nofollow">JMX system properties</a></p>

<p>For example you can enable remote JMX connections to the Sun JMX connector, via setting
the following environment variable (using <b>set</b> or <b>export</b>
depending on your platform). These settings only configure the Sun JMX connector within Java
1.5+, not the JMX connector that Camel creates by default.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
SUNJMX=-Dcom.sun.management.jmxremote=<span class="code-keyword">true</span> -Dcom.sun.management.jmxremote.port=1616
\
-Dcom.sun.management.jmxremote.authenticate=<span class="code-keyword">false</span>
-Dcom.sun.management.jmxremote.ssl=<span class="code-keyword">false</span>
</pre>
</div></div>
<p>(The SUNJMX environment variable is simple used by the startup script for Camel,
as additional startup parameters for the JVM. If you start Camel directly, you'll have to
pass these parameters yourself.)</p>

<h4><a name="CamelJMX-jmxAgentPropertiesReference"></a>jmxAgent Properties
Reference</h4>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Spring property </th>
<th class='confluenceTh'> System property </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> id </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The JMX agent name, and it is not optional </td>
</tr>
<tr>
<td class='confluenceTd'> usePlatformMBeanServer </td>
<td class='confluenceTd'> org.apache.camel.jmx.usePlatformMBeanServer </td>
<td class='confluenceTd'> false, true - Release 1.5 or later </td>
<td class='confluenceTd'> If true then it will use the plateform MBean server form the
JVM </td>
</tr>
<tr>
<td class='confluenceTd'> mbeanServerDefaultDomain </td>
<td class='confluenceTd'> org.apache.camel.jmx.mbeanServerDefaultDomain </td>
<td class='confluenceTd'> org.apache.camel </td>
<td class='confluenceTd'> The default JMX domain of the MBeanServer </td>
</tr>
<tr>
<td class='confluenceTd'> mbeanObjectDomainName </td>
<td class='confluenceTd'> org.apache.camel.jmx.mbeanObjectDomainName </td>
<td class='confluenceTd'> org.apache.camel </td>
<td class='confluenceTd'> The JMX domain that all objects names will use </td>
</tr>
<tr>
<td class='confluenceTd'> createConnector </td>
<td class='confluenceTd'> org.apache.camel.jmx.createRmiConnect </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> If we should create a JMX connector (to allow remote management)
for the MBeanServer </td>
</tr>
<tr>
<td class='confluenceTd'> registryPort </td>
<td class='confluenceTd'> org.apache.camel.jmx.rmiConnector.registryPort </td>
<td class='confluenceTd'> 1099 </td>
<td class='confluenceTd'> The port that the JMX RMI registry will use </td>
</tr>
<tr>
<td class='confluenceTd'> connectorPort </td>
<td class='confluenceTd'> org.apache.camel.jmx.rmiConnector.connectorPort </td>
<td class='confluenceTd'> &#45;1 (dynamic) </td>
<td class='confluenceTd'> The port that the JMX RMI server will use </td>
</tr>
<tr>
<td class='confluenceTd'> serviceUrlPath </td>
<td class='confluenceTd'> org.apache.camel.jmx.serviceUrlPath </td>
<td class='confluenceTd'> /jmxrmi/camel </td>
<td class='confluenceTd'> The path that JMX connector will be registered under </td>
</tr>
<tr>
<td class='confluenceTd'> onlyRegisterProcessorWithCustomId </td>
<td class='confluenceTd'> org.apache.camel.jmx.onlyRegisterProcessorWithCustomId </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> If this option is enabled then
only processors with a custom id set will be registered. This allows you to filer out unwanted
processors in the JMX console. </td>
</tr>
<tr>
<td class='confluenceTd'> statisticsLevel </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <tt>All</tt> </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> Configures the level for whether
performance statistics is enabled for the mbean. See section <em>Configuring level of
granularity for performance statistics</em> for more details. </td>
</tr>
</tbody></table>

<h3><a name="CamelJMX-RegisteringyourownManagedEndpoints"></a>Registering
your own Managed Endpoints</h3>
<p><b>Available as of Camel 2.0</b><br/>
You can decorate your own endpoints with spring managed annotations <b>@ManagedResource</b>
to allow to register them in the Camel mbean server and thus access your custom mbeans using
JMX.<br/>
<b>Notice:</b> in <b>Camel 2.1</b> we have changed this to apply other
than just endpoints but then you need to implement the interface <tt>org.apache.camel.spi.ManagementAware</tt>
as well. More about this later.</p>

<p>For example we have the following custom endpoint where we define some options to
be managed:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">@ManagedResource(description = <span class="code-quote">"Our
custom managed endpoint"</span>)
<span class="code-keyword">public</span> class CustomEndpoint <span class="code-keyword">extends</span>
MockEndpoint <span class="code-keyword">implements</span> ManagementAware&lt;CustomEndpoint&gt;
{

    <span class="code-keyword">public</span> CustomEndpoint(<span class="code-keyword">final</span>
<span class="code-object">String</span> endpointUri, <span class="code-keyword">final</span>
Component component) {
        <span class="code-keyword">super</span>(endpointUri, component);
    }

    <span class="code-keyword">public</span> <span class="code-object">Object</span>
getManagedObject(CustomEndpoint object) {
        <span class="code-keyword">return</span> <span class="code-keyword">this</span>;
    }

    <span class="code-keyword">public</span> <span class="code-object">boolean</span>
isSingleton() {
        <span class="code-keyword">return</span> <span class="code-keyword">true</span>;
    }

    <span class="code-keyword">protected</span> <span class="code-object">String</span>
createEndpointUri() {
        <span class="code-keyword">return</span> <span class="code-quote">"custom"</span>;
    }

    @ManagedAttribute
    <span class="code-keyword">public</span> <span class="code-object">String</span>
getFoo() {
        <span class="code-keyword">return</span> <span class="code-quote">"bar"</span>;
    }

    @ManagedAttribute
    <span class="code-keyword">public</span> <span class="code-object">String</span>
getEndpointUri() {
        <span class="code-keyword">return</span> <span class="code-keyword">super</span>.getEndpointUri();
    }
}
</pre>
</div></div>

<h3><a name="CamelJMX-ProgrammingyourownManagedServices"></a>Programming
your own Managed Services</h3>
<p><b>Available as of Camel 2.1</b></p>

<p>Camel now offers to use your own mbeans when registering services for management.
What that means is for example you can develop a custom Camel component and have it expose
mbeans for endpoints, consumers and producers etc. All you need to do is to implement the
interface <tt>org.apache.camel.spi.ManagementAware</tt> and return the managed
object Camel should use.</p>

<p>Now before you think oh boys the JMX API is really painful and terrible, then yeah
you are right. Lucky for us Spring though too and they created a range of annotations you
can use to export management on an existing bean. That means that you often use that and just
return <tt>this</tt> in the <tt>getManagedObject</tt> from the <tt>ManagementAware</tt>
interface. For an example see the code example above with the <tt>CustomEndpoint</tt>.</p>

<p>Now in Camel 2.1 you can do this for all the objects that Camel registers for management
which are quite a bunch, but not all. </p>

<p>For services which do not implement this <tt>ManagementAware</tt> interface
then Camel will fallback to using default wrappers as defined in the table below:</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> MBean wrapper </th>
</tr>
<tr>
<td class='confluenceTd'> CamelContext </td>
<td class='confluenceTd'> ManagedCamelContext </td>
</tr>
<tr>
<td class='confluenceTd'> Component </td>
<td class='confluenceTd'> ManagedComponent </td>
</tr>
<tr>
<td class='confluenceTd'> Endpoint </td>
<td class='confluenceTd'> ManagedEndpoint </td>
</tr>
<tr>
<td class='confluenceTd'> Consumer </td>
<td class='confluenceTd'> ManagedConsumer </td>
</tr>
<tr>
<td class='confluenceTd'> Producer </td>
<td class='confluenceTd'> ManagedProducer </td>
</tr>
<tr>
<td class='confluenceTd'> Route </td>
<td class='confluenceTd'> ManagedRoute </td>
</tr>
<tr>
<td class='confluenceTd'> Processor </td>
<td class='confluenceTd'> ManagedProcessor </td>
</tr>
<tr>
<td class='confluenceTd'> Tracer </td>
<td class='confluenceTd'> ManagedTracer </td>
</tr>
<tr>
<td class='confluenceTd'> Service </td>
<td class='confluenceTd'> ManagedService </td>
</tr>
</tbody></table>

<p>In addition to that there are some extended wrappers for specialized types such as</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> MBean wrapper </th>
</tr>
<tr>
<td class='confluenceTd'> ScheduledPollConsumer </td>
<td class='confluenceTd'> ManagedScheduledPollConsumer </td>
</tr>
<tr>
<td class='confluenceTd'> BrowsableEndpoint </td>
<td class='confluenceTd'> ManagedBrowseableEndpoint </td>
</tr>
<tr>
<td class='confluenceTd'> Throttler </td>
<td class='confluenceTd'> ManagedThrottler </td>
</tr>
<tr>
<td class='confluenceTd'> Delayer </td>
<td class='confluenceTd'> ManagedDelayer </td>
</tr>
<tr>
<td class='confluenceTd'> SendProcessor </td>
<td class='confluenceTd'> ManagedSendProcessor </td>
</tr>
</tbody></table>

<p>And in the future we will add additional wrappers for more EIP patterns.</p>

<h3><a name="CamelJMX-ManagementNamingStrategy"></a>ManagementNamingStrategy</h3>
<p><b>Available as of Camel 2.1</b></p>

<p>Camel provides a pluggable API for naming strategy by <tt>org.apache.camel.spi.ManagementNamingStrategy</tt>.
A default implementation is used to compute the mbean names that all mbeans are registered
with. </p>

<h3><a name="CamelJMX-ManagementStrategy"></a>ManagementStrategy</h3>
<p><b>Available as of Camel 2.1</b></p>

<p>Camel now provides a totally pluggable management strategy that allows you to be
100% in control of management. It is a rich interface with many methods for management. Not
only for adding and removing managed objects from the mbean server but also event notification
is provided as well using the <tt>org.apache.camel.spi.EventNotifier</tt> API.
What it does for example is to easier provide an adapter for other management products. In
additional it also allows you to provide more details and features that are provided out of
the box at Apache.</p>

<h3><a name="CamelJMX-Configuringlevelofgranularityforperformancestatistics"></a>Configuring
level of granularity for performance statistics</h3>
<p><b>Available as of Camel 2.1</b></p>

<p>You can now set a pre set level whether performance statistics is enabled or not
when Camel start ups. The levels are</p>
<ul class="alternate" type="square">
	<li><tt>All</tt> <b>default</b> - Camel will enable statistics
for both routes and processors (fine grained)</li>
	<li><tt>RoutesOnly</tt> - Camel will only enable statistics for routes
(coarse grained)</li>
	<li><tt>Off</tt> - Camel will not enable statistics for any.</li>
</ul>


<p>At runtime you can always use the management console (such as jconsole) to change
on a given route or processor whether its statistics are enabled or not.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>What does
statistics enabled mean?</b><br /><p>Statistics enabled means that Camel
will do fine grained performance statistics for that particular mbean. The statistics you
can see are many such as: number of exchanges completed/failed, last/total/mina/max/mean processing
time, first/last failed time etc.</p></td></tr></table></div>

<p>Using Java DSL you set this level by:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  <span class="code-comment">// only enable routes when Camel starts
</span>  context.getManagementStrategy().setSatisticsLevel(ManagementStatisticsLevel.RoutesOnly);
</pre>
</div></div>

<p>And from Spring DSL you do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
    <span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span>
xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
        <span class="code-tag">&lt;jmxAgent id=<span class="code-quote">"agent"</span>
statisticsLevel=<span class="code-quote">"RoutesOnly"</span>/&gt;</span>
     ...
    <span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<h3><a name="CamelJMX-Whichendpointsareregistered"></a>Which endpoints are
registered</h3>
<p>In <b>Camel 2.1</b> onwards <b>only</b> <tt>singleton</tt>
endpoints are registered as the overhead for non singleton will be substantial in cases where
thousands or millions of endpoints are used. This can happens when using a <a href="/confluence/display/CAMEL/Recipient+List"
title="Recipient List">Recipient List</a> EIP or from a <tt>ProducerTemplate</tt>
that sends a lot of messages.</p>

<h3><a name="CamelJMX-Whichprocessorsareregistered"></a>Which processors
are registered</h3>
<p>See <a href="/confluence/display/CAMEL/Why+is+my+processor+not+showing+up+in+JConsole"
title="Why is my processor not showing up in JConsole">this FAQ</a>.</p>

<h3><a name="CamelJMX-SeeAlso"></a>See Also</h3>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Management+Example" title="Management Example">Management
Example</a></li>
	<li><a href="/confluence/display/CAMEL/Why+is+my+processor+not+showing+up+in+JConsole"
title="Why is my processor not showing up in JConsole">Why is my processor not showing
up in JConsole</a></li>
</ul>

     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/Camel+JMX">View Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=85697&revisedVersion=31&originalVersion=30">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/Camel+JMX?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message