Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Ce contenu n'est pas disponible dans la langue sélectionnée.
2.11. Metrics
Overview
Copier lienLien copié sur presse-papiers!
					Available as of Camel 2.14
				
					While Camel provides a lot of existing metrics integration with Codahale metrics has been added for Camel routes. This allows end users to seamless feed Camel routing information together with existing data they are gathering using Codahale metrics.
				
					To use the Codahale metrics you will need to:
				
- Add camel-metrics component
- Enable route metrics in XML or Java code
					Note that performance metrics are only usable if you have a way of displaying them; any kind of monitoring tooling which can integrate with JMX can be used, as the metrics are available over JMX. In addition, the actual data is 100% Codehale JSON.
				
Metrics Route Policy
Copier lienLien copié sur presse-papiers!
					Obtaining Codahale metrics for a single route can be accomplished by defining a 
MetricsRoutePolicy on a per route basis.
				
					From Java create an instance of 
MetricsRoutePolicy to be assigned as the route's policy. This is shown below:
				from("file:src/data?noop=true").routePolicy(new MetricsRoutePolicy()).to("jms:incomingOrders");
from("file:src/data?noop=true").routePolicy(new MetricsRoutePolicy()).to("jms:incomingOrders");
					From XML DSL you define a 
<bean> which is specified as the route's policy; for example:
				Metrics Route Policy Factory
Copier lienLien copié sur presse-papiers!
					This factory allows one to add a 
RoutePolicy for each route which exposes route utilization statistics using Codahale metrics. This factory can be used in Java and XML as the examples below demonstrate.
				
					From Java you just add the factory to the 
CamelContext as shown below:
				context.addRoutePolicyFactory(new MetricsRoutePolicyFactory());
context.addRoutePolicyFactory(new MetricsRoutePolicyFactory());
					And from XML DSL you define a 
<bean> as follows:
				<!-- use camel-metrics route policy to gather metrics for all routes --> <bean id="metricsRoutePolicyFactory" class="org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFactory"/>
<!-- use camel-metrics route policy to gather metrics for all routes -->
<bean id="metricsRoutePolicyFactory" class="org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFactory"/>
					From Java code you can get hold of the 
com.codahale.metrics.MetricRegistry from the org.apache.camel.component.metrics.routepolicy.MetricsRegistryService as shown below:
				MetricRegistryService registryService = context.hasService(MetricsRegistryService.class);
if (registryService != null) {
  MetricsRegistry registry = registryService.getMetricsRegistry();
  ...
}
MetricRegistryService registryService = context.hasService(MetricsRegistryService.class);
if (registryService != null) {
  MetricsRegistry registry = registryService.getMetricsRegistry();
  ...
}Options
Copier lienLien copié sur presse-papiers!
					The 
MetricsRoutePolicyFactory and MetricsRoutePolicy supports the following options:
				| Name | Default | Description | 
|---|---|---|
| durationUnit | TimeUnit.MILLISECONDS | The unit to use for duration in the metrics reporter or when dumping the statistics as json. | 
| jmxDomain | org.apache.camel.metrics | The JXM domain name. | 
| metricsRegistry | Allow to use a shared com.codahale.metrics.MetricRegistry. If none is provided then Camel will create a shared instance used by the this CamelContext. | |
| prettyPrint | false | Whether to use pretty print when outputting statistics in json format. | 
| rateUnit | TimeUnit.SECONDS | The unit to use for rate in the metrics reporter or when dumping the statistics as json. | 
| useJmx | false | 
								Whether to report fine grained statistics to JMX by using the  com.codahale.metrics.JmxReporter.
								Notice that if JMX is enabled on CamelContext then a  MetricsRegistryServicembean is enlisted under the services type in the JMX tree. That mbean has a single operation to output the statistics using json. Setting useJmx to true is only needed if you want fine grained mbeans per statistics type. |