Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

Apache Camel has extensive support for JMX to allow you to monitor and control the Camel managed objects with a JMX client. Camel also provides a JMX component that allows you to subscribe to MBean notifications. This page is about how to manage and monitor Camel using JMX.

Activating JMX in Camel

Table of Contents

...

Spring JAR Dependencies Required By Camel 2.8 or Older

The following Spring jar files must be on the classpath in order for Camel to be able to use JMX instrumentation:

  • spring-context.jar
  • spring-aop.jar
  • spring-beans.jar
  • spring-core.jar

If these jar files are not on the classpath Camel will fallback to non JMX mode. Camel will log a warning to this affect using the logger: org.apache.camel.impl.DefaultCamelContext.

From Camel 2.9: the Spring jar files are no longer required for Camel to run in JMX mode.

Using JMX to manage Apache Camel

...

The DefaultManagementNamingStrategy is the default naming strategy which builds object names used for MBean registration. By default org.apache.camel 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:

...

Or, by adding a jmxAgent element inside the camelContext element in Spring configuration:

...

...

Spring configuration always takes precedence over system properties when they both present. It is true for all JMX related configurations.

...

You can disable JMX instrumentation agent by setting the Java VM system property as follow. The property value is treated as boolean.

...

...

Or, by adding a jmxAgent element inside the camelContext element in Spring configuration:

...

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:

...

...

Locating a MBeanServer in the Java VM

...

You can configure the matching default domain name via system property.

...

...

Or, by adding a jmxAgent element inside the camelContext element in Spring configuration:

...

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.

...

From Camel 1.5: the default value of usePlatformMBeanServer is true. Set the property to false to disable using platform MBeanServer.

...

Or, by adding a jmxAgent element inside the camelContext element in Spring configuration:

...

Creating JMX RMI Connector Server

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 MBeanServer used by Camel is attached to that connector server.

...

Or, by adding a jmxAgent element inside the camelContext element in Spring configuration:

...

...

JMX Service URL

The default JMX Service URL has the format:

...

where registryPort is the RMI registry port and the default value is 1099.

You can set the RMI registry port by system property.

...

Or, by adding a jmxAgent element inside the camelContext element in Spring configuration:

...

...

where serviceUrlPath is the path name in the URL and the default value is /jmxrmi/camel.

...

From Camel 2.4: various options can also be set on the ManagementAgent:

...

{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedServiceUrlPathTest.java}

Or, by adding a jmxAgent element inside the camelContext element in Spring configuration:

...

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.

...

...

Or by adding a jmxAgent element inside the camelContext element in Spring configuration:

...

When the connector port option is set, the JMX service URL will become:

...

...

System Properties for Camel JMX Support

...

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

...

...

JBoss AS 4

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

  • Tell Camel to use the Platform MBeanServer (This defaults to true in Camel 1.5)

...

...

...

Alter the mbeanServerDefaultDomain to be WebSphere

...

Oracle OC4j

The Oracle OC4J J2EE application server will not allow Camel to access the platform MBeanServer. You can identify this in the log as Camel will log a WARN.

...

...

To resolve this you should disable the JMX agent in Camel, see section Disabling JMX instrumentation agent in Camel

...

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.

Example:

...

...

If you wish to change the Java 5 JMX settings you can use various JMX system properties

For example you can enable remote JMX connections to the Sun JMX connector, via setting the following environment variable (using set or export 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.

...

...

(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.)

...

First you need to set up a JmxNotificationEventNotifier before you start the CamelContext. Wiki Markup{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxNotificationEventNotifierTest.java}Second you can register your listener for listening the event Wiki Markup{snippet:id=e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxNotificationEventNotifierTest.java}

Using the Tracer MBean to get fine grained tracing

...

For example we have the following custom endpoint where we define some options to be managed: Wiki Markup{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/management/CustomEndpoint.java}From Camel 2.9: it's encouraged that you use the @ManagedResource, @ManagedAttribute, and @ManagedOperation attributes from the org.apache.camel.api.management package. This allows your custom code to not depend on Spring JARs.

...

From Camel 2.10: we made it easier to configure a naming pattern for the MBeans. The pattern is used as part of the ObjectName as they key after the domain name. By default Camel will use MBean names for the ManagedCamelContextMBean as follows:

...

From Camel 2.13: the hostname is not included in the MBean names, so the above example would be as follows:

...

...

If you configure a name on the CamelContext then that name is part of the ObjectName as well. For example if we have

...

...

Then the MBean names will be as follows:

...

...

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 JMXMBeanServer by using a counter. As shown below the counter is now appended, so we have myCamel-1 as part of the ObjectName:

...

This is possible because Camel uses a naming pattern by default that supports the following tokens

...

Set a JVM system property to use a default management name pattern that prefixes the name with cool.

...

...

 

So if we want to explicit name both the CamelContext and to use fixed MBean names, that do not change e.g., has no counters, then we can use the new managementNamePattern attribute:

...

Then the MBean names will always be as follows:

...

In Java, you can configure the managementNamePattern as follows:

...

You can also use a different name in the managementNamePattern than the id, so for example we can do:

...

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:

...

...

Note this requires that myCamel is unique in the entire JVM. If you install a 2nd Camel application that has the same CamelContext id and managementNamePattern then Camel will fail upon starting, and report a MBean already exists exception.

...

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.

...

...

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.

Using Java DSL you set this level by:

...

...

And from Spring DSL you do:

...

...

Hiding sensitive information

...

Using Java DSL you turn this on by:

...

And from Spring DSL you do:

...

...

This will mask URIs having options such as password and passphrase, and use xxxxxx as the replacement value.

...

For example, on the default managed endpoints from camel-core org.apache.camel.api.management.mbean.ManagedEndpointMBean, we have declared that the EndpointUri JMX attribute is masked.

...

See Also