...
The metrics: component allows to collect various metrics directly from Camel routes. Supported metric types are counter, histogram, meter and timer. Metrics provides simple way to measure behaviour of application. Configurable reporting backend is enabling different integration options for collecting and visualizing statistics. The component also provides a MetricsRoutePolicyFactory
which allows to expose route statistics using codehale metrics, see bottom of page for details.
Maven users will need to add the following dependency to their pom.xml
for this component:
...
Each 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.
...
Code Block |
|
// sets timer action using header
from("direct:in")
.setHeader(MetricsConstants.HEADER_TIMER_ACTION, TimerAction.start)
.to("metric:timer:simple.timer")
.to("direct:out"); |
MetricsRoutePolicyFactory
This factory allows to add a RoutePolicy for each route which exposes route utilization statistics using codehale metrics. This factory can be used in Java and XML as the examples below demonstrates.
Tip |
Instead of using the MetricsRoutePolicyFactory you can define a MetricsRoutePolicy per route you want to instrument, in case you only want to instrument a few selected routes. |
From Java you just add the factory to the CamelContext
as shown below:
Code Block |
context.addRoutePolicyFactory(new MetricsRoutePolicyFactory());
|
And from XML DSL you define a <bean> as follows:
Code Block |
<!-- use camel-metrics route policy to gather metrics for all routes -->
<bean id="metricsRoutePolicyFactory" class="org.apache.camel.component.metrics.routepolicy.MetricsRoutePolicyFactory"/>
|
The MetricsRoutePolicyFactory
and MetricsRoutePolicy
supports the following options:
Name |
Default |
Description |
useJmx |
true |
Whether to report the statistics to JMX |
jmxDomain |
org.apache.camel.metrics |
The JMX 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. |
From Java code tou can get hold of the com.codahale.metrics.MetricRegistry
from the org.apache.camel.component.metrics.routepolicy.MetricsRegistryService
as shown below:
Code Block |
MetricRegistryService registryService = context.hasService(MetricsRegistryService.class);
if (registryService != null) {
MetricsRegistry registry = registryService.getMetricsRegistry();
...
}
|