Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
Metrics ComponentAvailable as of Camel 2.14 The The Maven users will need to add the following dependency to their <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-metrics</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency> URI Formatmetrics:[ meter | counter | histogram | timer ]:metricname[?options] Metric RegistryCamel Metrics Component uses by default For example using Spring Java Configuration: @Configuration public static class MyConfig extends SingleRouteCamelConfiguration { @Bean @Override public RouteBuilder route() { return new RouteBuilder() { @Override public void configure() throws Exception { // define Camel routes here } }; } @Bean(name = MetricsComponent.METRIC_REGISTRY_NAME) public MetricRegistry getMetricRegistry() { MetricRegistry registry = ...; return registry; } }
UsageEach metric has type and name. Supported types are counter, histogram, meter and timer. Metric name is simple string. If metric type is not provided then type meter is used by default. HeadersMetric name defined in URI can be overridden by using header with name For example from("direct:in") .setHeader(MetricsConstants.HEADER_METRIC_NAME, constant("new.name")) .to("metrics:counter:name.not.used") .to("direct:out"); will update counter with name All Metrics Type Countermetrics:counter:metricname[?options] Options
If neither // update counter simple.counter by 7 from("direct:in") .to("metric:counter:simple.counter?increment=7") .to("direct:out"); // increment counter simple.counter by 1 from("direct:in") .to("metric:counter:simple.counter") .to("direct:out"); // decrement counter simple.counter by 3 from("direct:in") .to("metric:counter:simple.counter?decrement=3") .to("direct:out"); HeadersMessage headers can be used to override
// update counter simple.counter by 417 from("direct:in") .setHeader(MetricsConstants.HEADER_COUNTER_INCREMENT, constant(417L)) .to("metric:counter:simple.counter?increment=7") .to("direct:out"); // updates counter using simple language to evaluate body.length from("direct:in") .setHeader(MetricsConstants.HEADER_COUNTER_INCREMENT, simple("${body.length}")) .to("metrics:counter:body.length") .to("mock:out"); Metric type histogrammetrics:histogram:metricname[?options] Options
If no // adds value 9923 to simple.histogram from("direct:in") .to("metric:histogram:simple.histogram?value=9923") .to("direct:out"); // nothing is added to simple.histogram; warning is logged from("direct:in") .to("metric:histogram:simple.histogram") .to("direct:out"); HeadersMessage header can be used to override value specified in
// Adds value 992 to simple.histogram from("direct:in") .setHeader(MetricsConstants.HEADER_HISTOGRAM_VALUE, constant(992L)) .to("metric:histogram:simple.histogram?value=700") .to("direct:out") Metric type metermetrics:meter:metricname[?options] Options
If // marks simple.meter without value from("direct:in") .to("metric:simple.meter") .to("direct:out"); // marks simple.meter with value 81 from("direct:in") .to("metric:meter:simple.meter?mark=81") .to("direct:out"); HeadersMessage header can be used to override
// updates meter simple.meter with value 345 from("direct:in") .setHeader(MetricsConstants.HEADER_METER_MARK, constant(345L)) .to("metric:meter:simple.meter?mark=123") .to("direct:out"); Metrics type timermetrics:timer:metricname[?options] Options
If no // measure time taken by route "calculate" from("direct:in") .to("metrics:timer:simple.timer?action=start") .to("direct:calculate") .to("metrics:timer:simple.timer?action=stop");
HeadersMessage header can be used to override action value specified in
// sets timer action using header from("direct:in") .setHeader(MetricsConstants.HEADER_TIMER_ACTION, TimerAction.start) .to("metric:timer:simple.timer") .to("direct:out");
|
Name | Default | Description |
---|---|---|
|
| Whether to report fine grained statistics to JMX by using the Notice that if JMX is enabled on CamelContext then a |
|
| The JMX domain name. |
|
| Whether to use pretty print when outputting statistics in JSON format. |
| Allow to use a shared | |
|
| The unit to use for rate in the metrics reporter or when dumping the statistics as JSON. |
|
| The unit to use for duration in the metrics reporter or when dumping the statistics as JSON. |
|
| Camel 2.17: The name pattern to use. Uses dot as separators, but you can change that. The values |
In Java you can get 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(); // ... }
MetricsMessageHistoryFactory
Available as of Camel 2.17
This factory allows to use metrics to capture Message History performance statistics while routing messages. It works by using a metrics Timer for each node in all the routes. This factory can be used in Java and XML as the examples below demonstrates.
In Java set the factory on the CamelContext
as shown below:
context.setMessageHistoryFactory(new MetricsMessageHistoryFactory());
And from XML DSL you define a <bean>
as follows:
<!-- use camel-metrics message history to gather metrics for all messages being routed --> <bean id="metricsMessageHistoryFactory" class="org.apache.camel.component.metrics.messagehistory.MetricsMessageHistoryFactory"/>
The following options is supported on the factory:
Name | Default | Description |
---|---|---|
|
| Whether to report fine grained statistics to JMX by using the Notice that if JMX is enabled on CamelContext then a |
|
| The JMX domain name. |
|
| Whether to use pretty print when outputting statistics in JSON format. |
| Allow to use a shared | |
|
| The unit to use for rate in the metrics reporter or when dumping the statistics as JSON. |
|
| The unit to use for duration in the metrics reporter or when dumping the statistics as JSON |
|
| The name pattern to use. Uses dot as separators, but you can change that. The values |
At runtime the metrics can be accessed from Java API or JMX which allows to gather the data as JSON output.
In Java, get the service from the CamelContext as shown:
MetricsMessageHistoryService service = context.hasService(MetricsMessageHistoryService.class); String json = service.dumpStatisticsAsJson();
And the JMX API the MBean is registered in the type=services
tree with name=MetricsMessageHistoryService
.