camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache Camel > Camel JMX
Date Tue, 05 Nov 2013 17:42:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Camel+JMX">Camel JMX</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| {{onlyRegisterProcessorWithCustomId}} | {{org.apache.camel.jmx.onlyRegisterProcessorWithCustomId}} | {{false}} | *Camel 2.0:* 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. | <br>| {{statisticsLevel}} | | {{All}} | *Camel 2.1:* Configures the level for whether performance statistics is enabled for the MBean. See section _Configuring level of granularity for performance statistics_ for more details. | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">| {{includeHostName}} | {{org.apache.camel.jmx.includeHostName}} | | *Camel 2.13:* Whether to include the hostname in the MBean naming. From Camel 2.13 onwards this is default {{false}}, where as in older releases its default {{true}}. You can use this option to restore old behavior if really needed. | <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h4. Configuring whether to register MBeans always, for new routes or just by default <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <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 with a JMX client.<br/>
Camel also provides a <a href="/confluence/display/CAMEL/JMX" title="JMX">JMX</a> component that allows you to subscribe to MBean notifications. This page is about how to manage and monitor Camel using JMX.</p>

<h3><a name="CamelJMX-ActivatingJMXinCamel"></a>Activating JMX in Camel</h3>

<div>
<ul>
    <li><a href='#CamelJMX-CamelJMX'>Camel JMX</a></li>
<ul>
    <li><a href='#CamelJMX-ActivatingJMXinCamel'>Activating JMX in Camel</a></li>
<ul>
    <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-TheSystemPropertiesforCamelJMXsupport'>The System Properties for Camel JMX support</a></li>
    <li><a href='#CamelJMX-HowtouseauthenticationwithJMX'>How to use authentication with JMX</a></li>
    <li><a href='#CamelJMX-JMXinsideanApplicationServer'>JMX inside an Application Server</a></li>
<ul>
    <li><a href='#CamelJMX-Tomcat6'>Tomcat 6</a></li>
    <li><a href='#CamelJMX-JBossAS4'>JBoss AS 4</a></li>
    <li><a href='#CamelJMX-WebSphere'>WebSphere</a></li>
    <li><a href='#CamelJMX-OracleOC4j'>Oracle OC4j</a></li>
</ul>
    <li><a href='#CamelJMX-AdvancedJMXConfiguration'>Advanced JMX Configuration</a></li>
    <li><a href='#CamelJMX-Example%3A'>Example:</a></li>
    <li><a href='#CamelJMX-jmxAgentPropertiesReference'>jmxAgent Properties Reference</a></li>
    <li><a href='#CamelJMX-ConfiguringwhethertoregisterMBeansalways%2Cfornewroutesorjustbydefault'>Configuring whether to register MBeans always, for new routes or just by default</a></li>
</ul>
    <li><a href='#CamelJMX-MonitoringCamelusingJMX'>Monitoring Camel using JMX</a></li>
<ul>
    <li><a href='#CamelJMX-UsingJConsoletomonitorCamel'>Using JConsole to monitor Camel</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-HowtousetheJMXNotificationListenertolistenthecamelevents%3F'>How to use the JMX NotificationListener to listen the camel events?</a></li>
    <li><a href='#CamelJMX-UsingtheTracerMBeantogetfinegrainedtracing'>Using the Tracer MBean to get fine grained tracing</a></li>
</ul>
    <li><a href='#CamelJMX-UsingJMXforyourownCamelCode'>Using JMX for your own Camel Code</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-Managementnamingpattern'>Management naming pattern</a></li>
    <li><a href='#CamelJMX-ManagementStrategy'>ManagementStrategy</a></li>
    <li><a href='#CamelJMX-Configuringlevelofgranularityforperformancestatistics'>Configuring level of granularity for performance statistics</a></li>
</ul>
    <li><a href='#CamelJMX-Hidingsensitiveinformation'>Hiding sensitive information</a></li>
<ul>
    <li><a href='#CamelJMX-DeclaringwhichJMXattributesandoperationstomask%28hidesensitiveinformation%29'>Declaring which JMX attributes and operations to mask (hide sensitive information)</a></li>
</ul>
    <li><a href='#CamelJMX-SeeAlso'>See Also</a></li>
</ul>
</ul></div>

<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>Spring JAR dependency, required for Camel 2.8 or older</b><br /><tt>spring-context.jar</tt>, <tt>spring-aop.jar</tt>, <tt>spring-beans.jar</tt>, and <tt>spring-core.jar</tt> are needed on the classpath by Camel to be able to use JMX instrumentation. If these .jars are not 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>From <b>Camel 2.9</b> onwards, the Spring JARs are <b>no</b> longer required to run Camel in JMX mode.</p></td></tr></table></div>

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

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

<p>The supported types of management objects are <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/management/mbean/ManagedEndpoint.html" class="external-link" rel="nofollow">endpoint</a>, <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/management/mbean/ManagedRoute.html" class="external-link" rel="nofollow">route</a>, <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/management/mbean/ManagedService.html" class="external-link" rel="nofollow">service</a>, and <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/management/mbean/ManagedProcessor.html" class="external-link" 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://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/management/DefaultManagementNamingStrategy.html" class="external-link" 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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
-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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"&gt;
  &lt;jmxAgent id="agent" mbeanObjectDomainName="your.domain.name"/&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 JMX related configurations.</p>

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

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

<p>Or in <b>Camel 2.1</b> 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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
CamelContext camel = new DefaultCamelContext();
camel.disableJMX();
</pre>
</div></div>

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

<p>Each CamelContext can have an instance of <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/spi/InstrumentationAgent.html" class="external-link" rel="nofollow">InstrumentationAgent</a> wrapped inside the <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/management/InstrumentationLifecycleStrategy.html" class="external-link" 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" class="external-link" rel="nofollow">MBeanServer</a> to register/unregister Camel MBeans. Multiple CamelContexts/InstrumentationAgents can/should share a <tt>MBeanServer</tt>. By default, Camel runtime picks the first <tt>MBeanServer</tt> returned by <a href="http://java.sun.com/j2se/1.5.0/docs/api/javax/management/MBeanServerFactory.html#findMBeanServer(java.lang.String)" class="external-link" rel="nofollow">MBeanServerFactory.findMBeanServer method</a> that matches the default domain name of <b>org.apache.camel</b>. You may want to change the default domain name to match the <tt>MBeanServer</tt> instance that you are already using in your application. Especially, if your <tt>MBeanServer</tt> 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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
-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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"&gt;
  &lt;jmxAgent id="agent" mbeanServerDefaultDomain="your.domain.name"/&gt;
    ...
&lt;/camelContext&gt;
</pre>
</div></div>
<p>If no matching <tt>MBeanServer</tt> can be found, a new one is created and the new <tt>MBeanServer</tt>'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()" class="external-link" rel="nofollow">PlatformMBeanServer</a> when it is desirable to manage JVM MBeans by setting the system property. The <tt>MBeanServer</tt> default domain name configuration is ignored as it is not applicable. <b>Starting in next release (1.5), the default value of <tt>usePlatformMBeanServer</tt> will be changed to "True". You can set the property to "False" to disable using platform <tt>MBeanServer</tt>.</b></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
-Dorg.apache.camel.jmx.usePlatformMBeanServer=True
</pre>
</div></div>
<p>Or, by adding a <b>jmxAgent</b> element inside the <tt>camelContext</tt> element in Spring configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"&gt;
  &lt;jmxAgent id="agent" usePlatformMBeanServer="true"/&gt;
    ...
&lt;/camelContext&gt;
</pre>
</div></div>

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

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

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

<p>The default JMX Service URL has the format:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
service:jmx:rmi:///jndi/rmi://localhost:&lt;registryPort&gt;/&lt;serviceUrlPath&gt;
</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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
-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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"&gt;
  &lt;jmxAgent id="agent" createConnector="true" registryPort="port number"/&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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
-Dorg.apache.camel.jmx.serviceUrlPath=&lt;path&gt;
</pre>
</div></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Setting ManagementAgent settings in Java</b><br />In <b>Camel 2.4</b> onwards you can also set the various options on the <tt>ManagementAgent</tt>:
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
context.getManagementStrategy().getManagementAgent().setServiceUrlPath("/foo/bar");
context.getManagementStrategy().getManagementAgent().setRegistryPort(2113);
context.getManagementStrategy().getManagementAgent().setCreateConnector(true);
]]></script>
</div></div></td></tr></table></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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"&gt;
  &lt;jmxAgent id="agent" createConnector="true" serviceUrlPath="path"/&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 connections established through a firewall. In such situations, 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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
-Dorg.apache.camel.jmx.rmiConnector.connectorPort=&lt;port number&gt;
</pre>
</div></div>
<p>Or, by adding a <b>jmxAgent</b> element inside the <tt>camelContext</tt> element in Spring configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"&gt;
  &lt;jmxAgent id="agent" createConnector="true" connectorPort="port number"/&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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
service:jmx:rmi://localhost:&lt;connectorPort&gt;/jndi/rmi://localhost:&lt;registryPort&gt;/&lt;serviceUrlPath&gt;
</pre>
</div></div>

<h4><a name="CamelJMX-TheSystemPropertiesforCamelJMXsupport"></a>The System Properties for Camel JMX support</h4>

<div class='table-wrap'>
<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>
</div>


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

<h4><a name="CamelJMX-HowtouseauthenticationwithJMX"></a>How to use authentication with JMX</h4>

<p>JMX in the JDK have features for authentication and also for using secure connections over SSL. You have to refer to the SUN documentation how to use this:</p>
<ul class="alternate" type="square">
	<li><a href="http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html" class="external-link" rel="nofollow">http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html</a></li>
	<li><a href="http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html" class="external-link" rel="nofollow">http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html</a></li>
</ul>


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

<h5><a name="CamelJMX-Tomcat6"></a>Tomcat 6</h5>

<p>See <a href="http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html" class="external-link" rel="nofollow">this page</a> for details about enabling JMX in Tomcat.</p>

<p>In short, modify your catalina.sh (or catalina.bat in Windows) file to set the following options...</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
 set CATALINA_OPTS=-Dcom.sun.management.jmxremote \
    -Dcom.sun.management.jmxremote.port=1099 \
    -Dcom.sun.management.jmxremote.ssl=false \
    -Dcom.sun.management.jmxremote.authenticate=false
</pre>
</div></div>

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

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

<p>1. Tell Camel to use the Platform <tt>MBeanServer</tt> (This defaults to true in Camel 1.5)</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;camel:camelContext id="camelContext"&gt;
  &lt;camel:jmxAgent id="jmxAgent" mbeanObjectDomainName="org.yourname" usePlatformMBeanServer="true"  /&gt;
&lt;/camel:camelContext&gt;
</pre>
</div></div>

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

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

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;camel:jmxAgent id="agent" createConnector="true" mbeanObjectDomainName="org.yourname" usePlatformMBeanServer="false" mbeanServerDefaultDomain="WebSphere"/&gt;
</pre>
</div></div>

<h5><a name="CamelJMX-OracleOC4j"></a>Oracle OC4j</h5>

<p>The Oracle OC4J J2EE application server will not allow Camel to access the platform <tt>MBeanServer</tt>. You can identify this in the log as Camel will log a <tt>WARNING</tt>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
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>

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

<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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"&gt;
  &lt;jmxAgent id="agent" createConnector="true" registryPort="2000" mbeanServerDefaultDomain="org.apache.camel.test"/&gt;
    &lt;route&gt;
      &lt;from uri="seda:start"/&gt;
      &lt;to uri="mock:result"/&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" class="external-link" 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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
SUNJMX=-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=1616 \
-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
</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>

<div class='table-wrap'>
<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'> <tt>id</tt> </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'> <tt>usePlatformMBeanServer</tt> </td>
<td class='confluenceTd'> <tt>org.apache.camel.jmx.usePlatformMBeanServer</tt> </td>
<td class='confluenceTd'> <tt>false</tt>, <tt>true</tt> - Release 1.5 or later </td>
<td class='confluenceTd'> If <tt>true</tt>, it will use the <tt>MBeanServer</tt> from the JVM </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mbeanServerDefaultDomain</tt> </td>
<td class='confluenceTd'> <tt>org.apache.camel.jmx.mbeanServerDefaultDomain</tt> </td>
<td class='confluenceTd'> <tt>org.apache.camel</tt> </td>
<td class='confluenceTd'> The default JMX domain of the <tt>MBeanServer</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mbeanObjectDomainName</tt> </td>
<td class='confluenceTd'> <tt>org.apache.camel.jmx.mbeanObjectDomainName</tt> </td>
<td class='confluenceTd'> <tt>org.apache.camel</tt> </td>
<td class='confluenceTd'> The JMX domain that all object names will use </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>createConnector</tt> </td>
<td class='confluenceTd'> <tt>org.apache.camel.jmx.createRmiConnect</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If we should create a JMX connector (to allow remote management) for the <tt>MBeanServer</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>registryPort</tt> </td>
<td class='confluenceTd'> <tt>org.apache.camel.jmx.rmiConnector.registryPort</tt> </td>
<td class='confluenceTd'> <tt>1099</tt> </td>
<td class='confluenceTd'> The port that the JMX RMI registry will use </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectorPort</tt> </td>
<td class='confluenceTd'> <tt>org.apache.camel.jmx.rmiConnector.connectorPort</tt> </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'> <tt>serviceUrlPath</tt> </td>
<td class='confluenceTd'> <tt>org.apache.camel.jmx.serviceUrlPath</tt> </td>
<td class='confluenceTd'> <tt>/jmxrmi/camel</tt> </td>
<td class='confluenceTd'> The path that JMX connector will be registered under </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onlyRegisterProcessorWithCustomId</tt> </td>
<td class='confluenceTd'> <tt>org.apache.camel.jmx.onlyRegisterProcessorWithCustomId</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </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'> <tt>statisticsLevel</tt> </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>
<tr>
<td class='confluenceTd'> <tt>includeHostName</tt> </td>
<td class='confluenceTd'> <tt>org.apache.camel.jmx.includeHostName</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>Camel 2.13:</b> Whether to include the hostname in the MBean naming. From Camel 2.13 onwards this is default <tt>false</tt>, where as in older releases its default <tt>true</tt>. You can use this option to restore old behavior if really needed. </td>
</tr>
</tbody></table>
</div>


<h4><a name="CamelJMX-ConfiguringwhethertoregisterMBeansalways%2Cfornewroutesorjustbydefault"></a>Configuring whether to register MBeans always, for new routes or just by default</h4>

<p><b>Available as of Camel 2.7</b></p>

<p>Camel now offers 2 settings to control whether or not to register mbeans</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>registerAlways</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If enabled then MBeans is always registered. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>registerNewRoutes</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> If enabled then adding new routes after <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a> has been started will also register MBeans from that given route. </td>
</tr>
</tbody></table>
</div>


<p>By default Camel registers MBeans for all the routes configured when its starting. The <tt>registerNewRoutes</tt> option control if MBeans should also be registered if you add new routes thereafter. You can disable this, if you for example add and remove temporary routes where management is not needed.</p>

<p>Be a bit caution to use the <tt>registerAlways</tt> option when using dynamic <a href="/confluence/display/CAMEL/EIP" title="EIP">EIP</a> patterns such as the <a href="/confluence/display/CAMEL/Recipient+List" title="Recipient List">Recipient List</a> having unique endpoints. If so then each unique endpoint and its associated services/producers would also be registered. This could potential lead to system degration due the rising number of mbeans in the registry. A MBean is not a light-weight object and thus consumes memory.</p>

<h3><a name="CamelJMX-MonitoringCamelusingJMX"></a>Monitoring Camel using JMX</h3>

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

<p>The <tt>CamelContext</tt> 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:service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi/camel</p>

<p>Using the Apache Camel with JConsole</p>

<p><span class="image-wrap" style=""><img src="/confluence/download/attachments/85697/camel-jmx.png?version=1&amp;modificationDate=1224680681000" style="border: 1px solid black" /></span></p>

<h4><a name="CamelJMX-Whichendpointsareregistered"></a>Which endpoints are registered</h4>

<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>

<h4><a name="CamelJMX-Whichprocessorsareregistered"></a>Which processors are registered</h4>

<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>

<h4><a name="CamelJMX-HowtousetheJMXNotificationListenertolistenthecamelevents%3F"></a>How to use the JMX NotificationListener to listen the camel events?</h4>

<p>The Camel notification events give a coarse grained overview what is happening. You can see lifecycle event from context and endpoints and you can see exchanges being received by and sent to endpoints.</p>

<p>From <b>Camel 2.4</b> you can use a custom JMX NotificationListener to listen the camel events.<br/>
First you need to set up a JmxNotificationEventNotifier before you start the CamelContext.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
// Set up the JmxNotificationEventNotifier
notifier = new JmxNotificationEventNotifier();
notifier.setSource("MyCamel");
notifier.setIgnoreCamelContextEvents(true);
notifier.setIgnoreRouteEvents(true);
notifier.setIgnoreServiceEvents(true);

CamelContext context = new DefaultCamelContext(createRegistry());
context.getManagementStrategy().addEventNotifier(notifier);

// Set up the ManagementNamingStrategy
DefaultManagementNamingStrategy naming = (DefaultManagementNamingStrategy) context.getManagementStrategy().getManagementNamingStrategy();
naming.setHostName("localhost");
naming.setDomainName("org.apache.camel");
]]></script>
</div></div>

<p>Second you can register your listener for listening the event</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
// register the NotificationListener
ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=eventnotifiers,name=JmxEventNotifier");
MyNotificationListener listener = new MyNotificationListener();   
context.getManagementStrategy().getManagementAgent().getMBeanServer().addNotificationListener(on,
    listener,                                                                                         
    new NotificationFilter() {            
        private static final long serialVersionUID = 1L;

        public boolean isNotificationEnabled(Notification notification) {
            return notification.getSource().equals("MyCamel");
        }
    }, null);

]]></script>
</div></div>

<h4><a name="CamelJMX-UsingtheTracerMBeantogetfinegrainedtracing"></a>Using the Tracer MBean to get fine grained tracing</h4>

<p>Additionally to the coarse grained notifications above <b>Camel 2.9.0</b> support JMX Notification for fine grained trace events.<br/>
These can be found in the Tracer MBean. To activate fine grained tracing you first need to activate tracing on the context or on a route.<br/>
This can either be done when configuring the context or on the context / route MBeans.</p>

<p>As a second step you have to set the <tt>jmxTraceNotifications</tt> attribute to <tt>true</tt> on the tracer. This can again be done when configuring the context or at runtime on the tracer MBean.</p>

<p>Now you can register for TraceEvent Notifications on the Tracer MBean using JConsole. There will be one Notification for every step on the route with all exchange and message details.</p>

<p><span class="image-wrap" style=""><img src="/confluence/download/attachments/85697/jconsole_trace_notifications.png?version=1&amp;modificationDate=1317961747000" style="border: 1px solid black" /></span></p>

<h3><a name="CamelJMX-UsingJMXforyourownCamelCode"></a>Using JMX for your own Camel Code</h3>

<h4><a name="CamelJMX-RegisteringyourownManagedEndpoints"></a>Registering your own Managed Endpoints</h4>

<p><b>Available as of Camel 2.0</b><br/>
You can decorate your own endpoints with Spring managed annotations <tt>@ManagedResource</tt> to allow to register them in the Camel <tt>MBeanServer</tt> 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">
<script type="syntaxhighlighter" class="theme: Default; brush: java; gutter: false"><![CDATA[
@ManagedResource(description = "Our custom managed endpoint")
public class CustomEndpoint extends MockEndpoint implements ManagementAware&lt;CustomEndpoint&gt; {

    public CustomEndpoint(final String endpointUri, final Component component) {
        super(endpointUri, component);
    }

    public Object getManagedObject(CustomEndpoint object) {
        return this;
    }

    public boolean isSingleton() {
        return true;
    }

    protected String createEndpointUri() {
        return "custom";
    }

    @ManagedAttribute
    public String getFoo() {
        return "bar";
    }

    @ManagedAttribute
    public String getEndpointUri() {
        return super.getEndpointUri();
    }
}
]]></script>
</div></div>

<p>Notice from <b>Camel 2.9</b> onwards its encouraged to use the <tt>@ManagedResource</tt>, <tt>@ManagedAttribute</tt>, and <tt>@ManagedOperation</tt> from the <tt>org.apache.camel.api.management</tt> package. This allows your custom code to not depend on Spring JARs.</p>

<h4><a name="CamelJMX-ProgrammingyourownManagedServices"></a>Programming your own Managed Services</h4>

<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 <b>Camel 2.1</b> 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>

<div class='table-wrap'>
<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>
</div>


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

<div class='table-wrap'>
<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>
</div>


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

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

<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>

<h4><a name="CamelJMX-Managementnamingpattern"></a>Management naming pattern</h4>
<p><b>Available as of Camel 2.10</b></p>

<p>From <b>Camel 2.10</b> onwards we made it easier to configure a naming pattern for the MBeans. The pattern is used as part of the <tt>ObjectName</tt> as they key after the domain name.</p>

<p>By default Camel will use MBean names for the <tt>ManagedCamelContextMBean</tt> as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
org.apache.camel:context=localhost/camel-1,type=context,name=camel-1
</pre>
</div></div>

<p>If you configure a name on the <tt>CamelContext</tt> then that name is part of the <tt>ObjectName</tt> as well. For example if we have</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;camelContext id="myCamel" ...&gt;
</pre>
</div></div>
<p>Then the MBean names will be as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
org.apache.camel:context=localhost/myCamel,type=context,name=myCamel
</pre>
</div></div>

<p>Now if there is a naming clash in the JVM, such as there already exists a MBean with that given name above, then Camel will by default try to auto correct this by finding a new free name in the <tt>JMXMBeanServer</tt> by using a counter. As shown below the counter is now appended, so we have <tt>myCamel-1</tt> as part of the <tt>ObjectName</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
org.apache.camel:context=localhost/myCamel-1,type=context,name=myCamel
</pre>
</div></div>

<p>This is possible because Camel uses a naming pattern by default that supports the following tokens</p>
<ul class="alternate" type="square">
	<li>#camelId# = the CamelContext id (eg the name)</li>
	<li>#name# - same as #camelId#</li>
	<li>#counter# - an incrementing counter</li>
	<li>#bundleId# - the OSGi bundle id (only for OSGi environments)</li>
	<li>#symbolicName# - the OSGi symbolic name (only for OSGi environments)</li>
	<li>#version# - the OSGi bundle version (only for OSGi environments)</li>
</ul>


<p>The default naming pattern is differentiated between OSGi and non-OSGi as follows:</p>
<ul class="alternate" type="square">
	<li>non OSGI: #name#</li>
	<li>OSGi: #bundleId#-#name#</li>
</ul>


<p>However if there is a naming clash in the <tt>JMXMBeanServer</tt> then Camel will automatic fallback and use the #counter# in the pattern to remedy this. And thus the following patterns will then be used:</p>
<ul class="alternate" type="square">
	<li>non OSGI: #name#-#counter#</li>
	<li>OSGi: #bundleId#&#45;#name#&#45;#counter#</li>
</ul>


<p>If you set an explicit naming pattern, then that pattern is always used, and the default patterns above is <b>not</b> used.<br/>
This allows us to have full control, very easily, of the naming for both the <tt>CamelContext</tt> id in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a> as well the JMX MBeans in the <tt>JMXMBeanRegistry</tt>.</p>

<p>So if we want to explicit name both the <tt>CamelContext</tt> and to use fixed MBean names, that do not change (eg has no counters), then we can use the new <tt>managementNamePattern</tt> attribute:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;camelContext id="myCamel" managementNamePattern="#name#"&gt;
</pre>
</div></div>
<p>Then the MBean names will always be as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
org.apache.camel:context=localhost/myCamel,type=context,name=myCamel
</pre>
</div></div>

<p>In Java, you can configure the <tt>managementNamePattern</tt> as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
context.getManagementNameStrategy().setNamePattern("#name#");
</pre>
</div></div>

<p>You can also use a different name in the <tt>managementNamePattern</tt> than the id, so for example we can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;camelContext id="myCamel" managementNamePattern="coolCamel"&gt;
</pre>
</div></div>

<p>You may want to do this in OSGi environments in case you do not want the OSGi bundle id as part of the MBean names. As the OSGi bundle id can change if you restart the server, or uninstall and install the same application. You can then do as follows to not use the OSGi bundle id as part of the name:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
&lt;camelContext id="myCamel" managementNamePattern="#name#"&gt;
</pre>
</div></div>
<p>Note this requires that <tt>myCamel</tt> is unique in the entire JVM. If you install a 2nd Camel application that has the same <tt>CamelContext</tt> id and <tt>managementNamePattern</tt> then Camel will fail upon starting, and report a MBean already exists exception.</p>

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

<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 <tt>MBeanServer</tt>, but also event notification is provided as well using the <tt>org.apache.camel.spi.EventNotifier</tt> API. What it does, for example, is make it easier to provide an adapter for other management products. In addition, it also allows you to provide more details and features that are provided out of the box at Apache.</p>

<h4><a name="CamelJMX-Configuringlevelofgranularityforperformancestatistics"></a>Configuring level of granularity for performance statistics</h4>

<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> &#45; Camel will enable statistics for both routes and processors (fine grained)</li>
	<li><tt>RoutesOnly</tt> &#45; Camel will only enable statistics for routes (coarse grained)</li>
	<li><tt>Off</tt> &#45; Camel will not enable statistics for any.</li>
</ul>


<p>From <b>Camel 2.9</b> onwards the performance statistics also include average load statistics per CamelContext and Route MBeans. The statistics is average load based on the number of in-flight exchanges, on a per 1, 5, and 15 minute rate. This is similar to load statistics on Unix systems. <b>Camel 2.11</b> onwards allows you to explicit disable load performance statistics by setting <tt>loadStatisticsEnabled=false</tt> on the &lt;jmxAgent&gt;. Note that it will be off if the statics level is configured to off as well.</p>

<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 />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.</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="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
  // only enable routes when Camel starts
  context.getManagementStrategy().setStatisticsLevel(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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
    &lt;camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"&gt;
        &lt;jmxAgent id="agent" statisticsLevel="RoutesOnly"/&gt;
     ...
    &lt;/camelContext&gt;
</pre>
</div></div>


<h3><a name="CamelJMX-Hidingsensitiveinformation"></a>Hiding sensitive information</h3>
<p><b>Available as of Camel 2.12</b></p>

<p>By default, Camel enlists MBeans in JMX such as endpoints configured using <a href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a>. In this configuration, there may be sensitive information such as passwords. <br/>
This information can be hidden by enabling the <tt>mask</tt> option as shown below:</p>

<p>Using Java DSL you turn this on by:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
  // only enable routes when Camel starts
  context.getManagementStrategy().getManagementAgent().setMask(true);
</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="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
    &lt;camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"&gt;
        &lt;jmxAgent id="agent" mask="true"/&gt;
     ...
    &lt;/camelContext&gt;
</pre>
</div></div>

<p>This will mask <a href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a> having options such as password and passphrase, and use <tt>xxxxxx</tt> as the replacement value.</p>

<h4><a name="CamelJMX-DeclaringwhichJMXattributesandoperationstomask%28hidesensitiveinformation%29"></a>Declaring which JMX attributes and operations to mask (hide sensitive information)</h4>

<p>On the <tt>org.apache.camel.api.management.ManagedAttribute</tt> and <tt>org.apache.camel.api.management.ManagedOperation</tt>, the attribute <tt>mask</tt> can be set to <tt>true</tt> to indicate that the result of this JMX attribute/operation should be masked (if enabled on JMX agent, see above).</p>

<p>For example, on the default managed endpoints from camel-core <tt>org.apache.camel.api.management.mbean.ManagedEndpointMBean</tt>, we have declared that the <tt>EndpointUri</tt> JMX attribute is masked.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
    @ManagedAttribute(description = "Endpoint URI", mask = true)
    String getEndpointUri();
</pre>
</div></div>


<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;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CAMEL">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Camel+JMX">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=85697&revisedVersion=62&originalVersion=61">View Changes</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message