Camel JMXPage edited by Claus IbsenChanges (3)
Full ContentCamel JMXApache Camel has extensive support for JMX to allow you to monitor and control the Camel managed objects with a JMX client. Activating JMX in Camel
Using JMX to manage Apache CamelBy 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. The supported types of management objects are endpoint , route, service, and processor. Some of these management objects also expose lifecycle operations in addition to performance counter attributes. 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: -Dorg.apache.camel.jmx.mbeanObjectDomainName=your.domain.name Or, by adding a jmxAgent element inside the camelContext element in Spring configuration: <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <jmxAgent id="agent" mbeanObjectDomainName="your.domain.name"/> ... </camelContext> Spring configuration always takes precedence over system properties when they both present. It is true for all of JMX related configurations.
JMX inside an Application ServerTomcat 6See this page for details about enabling JMX in Tomcat. In short, modify your catalina.sh (or catalina.bat in Windows) file to set the following options... 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 JBoss AS 4By default JBoss creates its own MBean server. To allow Camel to expose to the same server follow these steps: 1. Tell Camel to use the Platform MBean Server (This defaults to true in Camel 1.5) <camel:camelContext id="camelContext"> <camel:jmxAgent id="jmxAgent" mbeanObjectDomainName="org.yourname" usePlatformMBeanServer="true" /> </camel:camelContext> 2. Alter your JBoss instance to use the Platform MBean server. WebSphereAlter the mbeanServerDefaultDomain to be "WebSphere" <camel:jmxAgent id="agent" createConnector="true" mbeanObjectDomainName="org.yourname" usePlatformMBeanServer="false" mbeanServerDefaultDomain="WebSphere"/> Oracle OC4jThe 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. 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) To resolve this you should disable the JMX agent in Camel, see section Disabling JMX instrumentation agent in Camel Advanced JMX ConfigurationThe 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:<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <jmxAgent id="agent" createConnector="true" registryPort="2000" mbeanServerDefaultDomain="org.apache.camel.test"/> <route> <from uri="seda:start"/> <to uri="mock:result"/> </route> </camelContext> 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. SUNJMX=-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=1616 \ -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false (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.) jmxAgent Properties Reference
Configuring whether to register mbeans always, for new routes or just by defaultAvailable as of Camel 2.7 Camel now offers 2 settings to control whether or not to register mbeans
By default Camel registers mbeans for all the routes configured when its starting. The registerNewRoutes 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. Be a bit caution to use the registerAlways option when using dynamic EIP patterns such as the Recipient List 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 consume memory. Monitoring Camel using JMXUsing JConsole to monitor CamelThe CamelContext should appear in the list of local connections, if you are running JConsole on the same host as Camel. 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 Using the Apache Camel which Jconsole Which endpoints are registeredIn Camel 2.1 onwards only singleton 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 Recipient List EIP or from a ProducerTemplate that sends a lot of messages. Which processors are registeredSee this FAQ. How to use the JMX NotificationListener to listen the camel events?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. From Camel 2.4 you can use a customer JMX NotificationListener to listen the camel events. // 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"); Second you can register your listener for listening the event // 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); Using the Tracer mbean to get fine grained tracingAdditionally to the coarse grained notifications above Camel > 2.9.0 support JMX Notification for fine grained trace events. As a second step you have to set the jmxTraceNotifications attribute to true on the tracer. This can again be done when configuring the context or at runtime on the tracer mbean. 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. Using JMX for your own Camel CodeRegistering your own Managed EndpointsAvailable as of Camel 2.0 For example we have the following custom endpoint where we define some options to be managed: @ManagedResource(description = "Our custom managed endpoint") public class CustomEndpoint extends MockEndpoint implements ManagementAware<CustomEndpoint> { 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(); } } Notice from Camel 2.9 onwards its encouraged to use the @ManagedResource, @ManagedAttribute, and @ManagedOperation from the org.apache.camel.management.ManagedResource package. This allows your custom code to not depend on Spring JARs. Programming your own Managed ServicesAvailable as of Camel 2.1 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 org.apache.camel.spi.ManagementAware and return the managed object Camel should use. 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 this in the getManagedObject from the ManagementAware interface. For an example see the code example above with the CustomEndpoint. 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. For services which do not implement this ManagementAware interface then Camel will fallback to using default wrappers as defined in the table below:
In addition to that there are some extended wrappers for specialized types such as
And in the future we will add additional wrappers for more EIP patterns. ManagementNamingStrategyAvailable as of Camel 2.1 Camel provides a pluggable API for naming strategy by org.apache.camel.spi.ManagementNamingStrategy. A default implementation is used to compute the mbean names that all mbeans are registered with. Management naming patternAvailable as of Camel 2.10 From Camel 2.10 onwards 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: org.apache.camel:context=localhost/camel-1,type=context,name=camel-1 If you configure a name on the CamelContext then that name is part of the ObjectName as well. For example if we have
<camelContext id="myCamel" ...>
Then the MBean names will be as follows: org.apache.camel:context=localhost/myCamel,type=context,name=myCamel 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: org.apache.camel:context=localhost/myCamel-1,type=context,name=myCamel This is possible because Camel uses a naming pattern by default that supports the following tokens
The default naming pattern is differentiated between OSGi and non-OSGi as follows:
However if there is a naming clash in the JMXMBeanServer then Camel will automatic fallback and use the #counter# in the pattern to remedy this. And thus the following patterns will then be used:
If you set an explicit naming pattern, then that pattern is always used, and the default patterns above is not used. So if we want to explicit name both the CamelContext and to use fixed mbean names, that do not change (eg has no counters), then we can use the new managementNamePattern attribute:
<camelContext id="myCamel" managementNamePattern="#name#">
Then the MBean names will always be as follows: org.apache.camel:context=localhost/myCamel,type=context,name=myCamel In Java you can configure the managementNamePattern as follows:
context.getManagementNameStrategy().setNamePattern("#name#");
You can also use a different name in the managementNamePattern than the id, so for example we can do:
<camelContext id="myCamel" managementNamePattern="coolCamel">
You may want to do this in OSGi environments in case you do not want the bundleId as part of the mbean names. As the 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 bundleId as part of the name:
<camelContext id="myCamel" managementNamePattern="#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. ManagementStrategyAvailable as of Camel 2.1 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 org.apache.camel.spi.EventNotifier 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. Configuring level of granularity for performance statisticsAvailable as of Camel 2.1 You can now set a pre set level whether performance statistics is enabled or not when Camel start ups. The levels are
From Camel 2.9 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. 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.
Using Java DSL you set this level by:
// only enable routes when Camel starts
context.getManagementStrategy().setSatisticsLevel(ManagementStatisticsLevel.RoutesOnly);
And from Spring DSL you do: <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <jmxAgent id="agent" statisticsLevel="RoutesOnly"/> ... </camelContext> See Also
Change Notification Preferences
View Online
|
View Changes
|
Add Comment
|
- [CONF] Apache Camel > Camel JMX confluence
- [CONF] Apache Camel > Camel JMX confluence
- [CONF] Apache Camel > Camel JMX confluence
- [CONF] Apache Camel > Camel JMX confluence