MicroProfile Metrics
Since Camel 3.0
Only producer is supported
The MircoProfile Metrics component provides the capability to expose metrics from Camel routes.
Maven users need to add the following dependency to their pom.xml
for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-microprofile-metrics</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
It is expected that the component is running in a MicroProfile environment that provides an appropriate implementation of MicroProfile Metrics 2.0. E.g SmallRye Metrics.
URI format
microprofile-metrics:[ concurrent gauge | counter | gauge | histogram | meter | timer ]:metricname[?options]
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
The component level is the highest level which holds general and common configurations that are inherited by the endpoints. For example a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.
Configuring Endpoint Options
Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.
The following two sections lists all the options, firstly for the component followed by the endpoint.
Component Options
The MicroProfile Metrics component supports 3 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
Use a custom MetricRegistry. | MetricRegistry |
Endpoint Options
The MicroProfile Metrics endpoint is configured using URI syntax:
microprofile-metrics:metricType:metricName
with the following path and query parameters:
Query Parameters (12 parameters)
Name | Description | Default | Type |
---|---|---|---|
Action to use when using the timer type. | String | ||
Increment value when using the counter type. | Long | ||
Metric description. | String | ||
Metric display name. | String | ||
Decrement metric value when using concurrent gauge type. | Boolean | ||
Increment metric value when using the concurrent gauge type. | Boolean | ||
Decrement metric value when using concurrent gauge type. | Number | ||
Mark value to set when using the meter type. | Long | ||
Metric unit. See org.eclipse.microprofile.metrics.MetricUnits. | String | ||
Comma delimited list of tags associated with the metric in the format tagName=tagValue. | String | ||
Value to set when using the histogram type. | Long | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean |
Message Headers
The MicroProfile Metrics component supports 13 message header(s), which is/are listed below:
Name | Description | Default | Type |
---|---|---|---|
CamelMicroProfileMetricsCounterIncrement (producer) Constant: | Override increment value in URI. | long | |
CamelMicroProfileMetricsGaugeIncrement (producer) Constant: | Override gaugeIncrement value from the URI. | Boolean | |
CamelMicroProfileMetricsGaugeDecrement (producer) Constant: | Override gaugeDecrement value from the URI. | Boolean | |
CamelMicroProfileMetricsGaugeValue (producer) Constant: | Override gaugeValue value from the URI. | Number | |
CamelMicroProfileMetricsHistogramValue (producer) Constant: | Override histogram value from the URI. | Long | |
CamelMicroProfileMetricsMeterMark (producer) Constant: | Override meter mark value from the URI. | Long | |
CamelMicroProfileMetricsDescription (producer) Constant: | The description within the metric metadata. | String | |
CamelMicroProfileMetricsDisplayName (producer) Constant: | The display name within the metric metadata. | String | |
CamelMicroProfileMetricsName (producer) Constant: | The name of the metric. | String | |
CamelMicroProfileMetricsTags (producer) Constant: | The tags of the metric. | String | |
CamelMicroProfileMetricsType (producer) Constant: | The type of the metric. Enum values:
| MetricType | |
CamelMicroProfileMetricsUnits (producer) Constant: | The metric unit within the metric metadata. | String | |
CamelMicroProfileMetricsTimerAction (producer) Constant: | Override time action from the URI. Enum values:
| TimerAction |
MetricRegistry Configuration
Configure a MetricRegistry
to use either by passing it to the MicroProfileMetricsComponent.
MicroProfileMetricsComponent component = new MicroProfileMetricsComponent();
component.setRegistry(myMetricRegistryImpl);
Or by binding it to the Camel registry using the binding name 'metricRegistry' (See MicroProfileMetricsConstants.METRIC_REGISTRY_NAME
).
Default Camel Metrics
Some Camel specific metrics are available out of the box.
Name | Type | Description |
---|---|---|
application_camel_message_history_processing | timer | Sample of performance of each node in the route when message history is enabled |
application_camel_route_count | gauge | Number of routes added |
application_camel_route_running_count | gauge | Number of routes runnning |
application_camel_[route or context]_exchanges_inflight_count | gauge | Route inflight messages for a CamelContext or a route |
application_camel_[route or context]_exchanges_total | counter | Total number of processed exchanges for a CamelContext or a route |
application_camel_[route or context]_exchanges_completed_total | counter | Number of successfully completed exchange for a CamelContext or a route |
application_camel_[route or context]_exchanges_failed_total | counter | Number of failed exchanges for a CamelContext or a route |
application_camel_[route or context]_failuresHandled_total | counter | Number of failures handled for a CamelContext or a route |
application_camel_[route or context]_externalRedeliveries_total | counter | Number of external initiated redeliveries (such as from JMS broker) for a CamelContext or a route |
application_camel_context_status | gauge | The status of the Camel Context |
application_camel_context_uptime_seconds | gauge | The amount of time since the Camel Context was started |
application_camel_[route or exchange]processing[rate_per_second or one_min_rate_per_second or five_min_rate_per_second or fifteen_min_rate_per_second or min_seconds or max_seconds or mean_second or stddev_seconds] | gauge | Exchange message or route processing with multiple options |
application_camel_[route or exchange]_processing_seconds | summary | Exchange message or route processing metric |
Counter
microprofile-metrics:counter:name[?options]
Options
Name | Default | Description |
---|---|---|
counterIncrement | - | Value to add to the counter |
If counterIncrement
is not defined then counter value will be incremented by one.
// Increment counter simple.counter by 7
from("direct:in")
.to("microprofile-metrics:counter:simple.counter?counterIncrement=7")
.to("direct:out");
// Increment counter simple.counter by 1
from("direct:in")
.to("microprofile-metrics:counter:simple.counter")
.to("direct:out");
Headers
Message headers can be used to override the counterIncrement
values specified on the microprofile-metrics
endpoint URI.
Name | Description | Expected type |
---|---|---|
CamelMicroProfileMetricsCounterIncrement | Override increment value from the URI | Long |
// Increment counter simple.counter by 417
from("direct:in")
.setHeader(MicroProfileMetricsConstants.HEADER_COUNTER_INCREMENT, constant(417))
.to("microprofile-metrics:counter:simple.counter?increment=7")
.to("direct:out");
Concurrent Gauge
microprofile-metrics:concurrent gauge:name[?options]
Options
Name | Default | Description |
---|---|---|
gaugeIncrement | false | Value to add to the counter |
gaugeDecrement | false | Value to add to the counter |
If neither gaugeIncrement
or gaugeDecrement
are defined then no action is performed on the gauge.
// Increment concurrent gauge simple.gauge by 1
from("direct:in")
.to("microprofile-metrics:concurrent gauge:simple.gauge?gaugeIncrement=true")
.to("direct:out");
// Decrement concurrent gauge simple.gauge by 1
from("direct:in")
.to("microprofile-metrics:concurrent gauge:simple.gauge?gaugeDecrement=true")
.to("direct:out");
Headers
Message headers can be used to override the gaugeIncrement
and gaugeDecrement
values specified on the microprofile-metrics
endpoint URI.
Name | Description | Expected type |
---|---|---|
CamelMicroProfileMetricsGaugeIncrement | Override gaugeIncrement value from the URI | Boolean |
CamelMicroProfileMetricsGaugeDecrement | Override gaugeDecrement value from the URI | Boolean |
// Increment concurrent gauge simple.gauge by 1
from("direct:in")
.setHeader(MicroProfileMetricsConstants.HEADER_GAUGE_INCREMENT, constant(true))
.to("microprofile-metrics:concurrent gauge:simple.gauge")
.to("direct:out");
// Decrement concurrent gauge simple.gauge by 1
from("direct:in")
.setHeader(MicroProfileMetricsConstants.HEADER_GAUGE_DECREMENT, constant(true))
.to("microprofile-metrics:concurrent gauge:simple.gauge")
.to("direct:out");
Gauge
microprofile-metrics:gauge:name[?options]
Options
Name | Default | Description |
---|---|---|
gaugeValue | false | Value to set the gauge to |
If gaugeValue
is not defined then no action is performed on the gauge.
// Set gauge simple.gauge value to 10
from("direct:in")
.to("microprofile-metrics:gauge:simple.gauge?gaugeValue=10")
.to("direct:out");
Headers
Message headers can be used to override the gaugeValue
value specified on the microprofile-metrics
endpoint URI.
Name | Description | Expected type |
---|---|---|
CamelMicroProfileMetricsGaugeValue | Override gaugeValue value from the URI | Number |
// Set gauge simple.gauge value to 10
from("direct:in")
.setHeader(MicroProfileMetricsConstants.HEADER_GAUGE_VALUE, constant(10))
.to("microprofile-metrics:gauge:simple.gauge")
.to("direct:out");
Histogram
microprofile-metrics:histogram:name[?options]
Options
Name | Default | Description |
---|---|---|
value | - | Value to set on the histogram |
If value
is not defined then histogram value will not be changed.
// Set histogram simple.histogram to 7
from("direct:in")
.to("microprofile-metrics:histogram:simple.histogram?value=7")
.to("direct:out");
Headers
Message headers can be used to override the value
specified on the microprofile-metrics
endpoint URI.
Name | Description | Expected type |
---|---|---|
CamelMicroProfileMetricsHistogramValue | Override histogram value from the URI | Long |
// Set histogram simple.histogram to 417
from("direct:in")
.setHeader(MicroProfileMetricsConstants.HEADER_HISTOGRAM_VALUE, constant(417))
.to("microprofile-metrics:histogram:simple.histogram?value=7")
.to("direct:out");
Meter
microprofile-metrics:meter:name[?options]
Options
Name | Default | Description |
---|---|---|
mark | - | Mark value to set on the meter |
If mark
is not defined then the meter will be marked with the value '1'.
// Mark the meter simple.meter with 7
from("direct:in")
.to("microprofile-metrics:meter:simple.meter?mark=7")
.to("direct:out");
// Mark the meter simple.meter with 1
from("direct:in")
.to("microprofile-metrics:meter:simple.meter")
.to("direct:out");
Headers
Message headers can be used to override the value
specified on the microprofile-metrics
endpoint URI.
Name | Description | Expected type |
---|---|---|
CamelMicroProfileMetricsMeterMark | Override meter mark value from the URI | Long |
// Mark the meter simple.meter with 417
from("direct:in")
.setHeader(MicroProfileMetricsConstants.HEADER_METER_MARK, constant(417))
.to("microprofile-metrics:meter:simple.meter?value=7")
.to("direct:out");
Timer
microprofile-metrics:timer:name[?options]
Options
Name | Default | Description |
---|---|---|
action | - | start or stop |
If no action
is specified or it’s an invalid value, then no timer update occurs.
If the start
action is called on an already running timer or stop
is called on an unknown timer, then no timer(s) are updated.
// Measure time spent in route `direct:calculate`
from("direct:in")
.to("microprofile-metrics:timer:simple.timer?action=start")
.to("direct:calculate")
.to("microprofile-metrics:timer:simple.timer?action=stop");
Headers
Message headers can be used to override the action
specified on the microprofile-metrics
endpoint URI.
Name | Description | Expected type |
---|---|---|
CamelMicroProfileMetricsTimerAction | Override time action from the URI | org.apache.camel.component.microprofile.metrics.TimerAction |
// Mark the meter simple.meter with 417
from("direct:in")
.setHeader(MicroProfileMetricsConstants.HEADER_TIMER_ACTION, TimerAction.START)
.to("microprofile-metrics:timer:simple.timer")
.to("direct:out");
MicroProfileMetricsRoutePolicyFactory
This factory allows to add a RoutePolicy for each route and exposes route utilization statistics using MicroProfile metrics.
Instead of using the MicroProfileMetricsRoutePolicyFactory you can define a MicroProfileMetricsRoutePolicy per route you want to instrument, in case you only want to instrument a few selected routes. |
Add the factory to the CamelContext
as shown below:
context.addRoutePolicyFactory(new MicroProfileMetricsRoutePolicyFactory());
MicroProfileMetricsMessageHistoryFactory
This factory captures message history performance statistics while routing messages.
Add the factory to the CamelContext
as shown below:
context.setMessageHistoryFactory(new MicroProfileMetricsMessageHistoryFactory());
MicroProfileMetricsExchangeEventNotifier
The exchange event notifier times exchanges from creation through to completion.
EventNotifiers can be added to the CamelContext
, e.g.:
camelContext.getManagementStrategy().addEventNotifier(new MicroProfileMetricsExchangeEventNotifier())