This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Metrics Component

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
// sets timer action using header
from("direct:in")
    .setHeader(MetricsConstants.HEADER_TIMER_ACTION, TimerAction.start)
    .to("metric:timer:simple.timer")
    .to("direct:out");

 

MetricsRoutePolicyFactory

...

NameDefaultDescription
useJmxfalseWhether to report fine grained statistics to JMX by using the com.codahale.metrics.JmxReporter.
Notice that if JMX is enabled on CamelContext then a MetricsRegistryService mbean 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.
jmxDomainorg.apache.camel.metricsThe JMX domain name
prettyPrintfalseWhether to use pretty print when outputting statistics in json format
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.
rateUnitTimeUnit.SECONDSThe unit to use for rate in the metrics reporter or when dumping the statistics as json.
durationUnitTimeUnit.MILLISECONDSThe unit to use for duration in the metrics reporter or when dumping the statistics as json.
namePattern##name##.##routeId##.##type##Camel 2.17: The name pattern to use. Uses dot as separators, but you can change that. The values ##name##, ##routeId##, and ##type## will be replaced with actual value. Where ###name### is the name of the CamelContext. ###routeId### is the name of the route. And ###type### is the value of responses.

 

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

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. 

From Java you just set the factory to the CamelContext as shown below:

Code Block
context.setMessageHistoryFactory(new MetricsMessageHistoryFactory());

And from XML DSL you define a <bean> as follows:

Code Block
  <!-- 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:

NameDefaultDescription
useJmxfalseWhether to report fine grained statistics to JMX by using the com.codahale.metrics.JmxReporter.
Notice that if JMX is enabled on CamelContext then a MetricsRegistryService mbean 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.
jmxDomainorg.apache.camel.metricsThe JMX domain name
prettyPrintfalseWhether to use pretty print when outputting statistics in json format
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.
rateUnitTimeUnit.SECONDSThe unit to use for rate in the metrics reporter or when dumping the statistics as json.
durationUnitTimeUnit.MILLISECONDSThe unit to use for duration in the metrics reporter or when dumping the statistics as json.
namePattern##name##.##routeId##.###id###.##type##The name pattern to use. Uses dot as separators, but you can change that. The values ##name##, ##routeId##, ##type##, and ###id### will be replaced with actual value. Where ###name### is the name of the CamelContext. ###routeId### is the name of the route. The ###id### pattern represents the node id. And ###type### is the value of history.

At runtime the metrics can be accessed from Java API or JMX which allows to gather the data as json output.

From Java code you can do get the service from the CamelContext as shown:

Code Block
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