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]

Options

The MicroProfile Metrics component supports 3 options, which are listed below.

Name Description Default Type

lazyStartProducer (producer)

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

basicPropertyBinding (advanced)

Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities

false

boolean

metricRegistry (advanced)

Use a custom MetricRegistry.

MetricRegistry

The MicroProfile Metrics endpoint is configured using URI syntax:

microprofile-metrics:metricType:metricName

with the following path and query parameters:

Path Parameters (2 parameters):

Name Description Default Type

metricType

Required Metric type. The value can be one of: concurrent gauge, counter, gauge, meter, histogram, timer, simple timer, invalid

MetricType

metricName

Required Metric name

String

Query Parameters (14 parameters):

Name Description Default Type

action (producer)

Action to use when using the timer type

String

counterIncrement (producer)

Increment value when using the counter type

Long

description (producer)

Metric description

String

displayName (producer)

Metric display name

String

gaugeDecrement (producer)

Decrement metric value when using concurrent gauge type

Boolean

gaugeIncrement (producer)

Increment metric value when using the concurrent gauge type

Boolean

gaugeValue (producer)

Decrement metric value when using concurrent gauge type

Number

lazyStartProducer (producer)

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

mark (producer)

Mark value to set when using the meter type

Long

metricUnit (producer)

Metric unit. See org.eclipse.microprofile.metrics.MetricUnits

String

tags (producer)

Comma delimited list of tags associated with the metric in the format tagName=tagValue

String

value (producer)

Value to set when using the histogram type

Long

basicPropertyBinding (advanced)

Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities

false

boolean

synchronous (advanced)

Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported).

false

boolean

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).

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())

MicroProfileMetricsRouteEventNotifier

The route event notifier counts added and running routes within the CamelContext.

EventNotifiers can be added to the CamelContext, e.g.:

camelContext.getManagementStrategy().addEventNotifier(new MicroProfileMetricsRouteEventNotifier())

MicroProfileMetricsCamelContextEventNotifier

The Camel Context event notifier adds some basic metrics about the state of the CamelContext.

EventNotifiers can be added to the CamelContext, e.g.:

camelContext.getManagementStrategy().addEventNotifier(new MicroProfileMetricsCamelContextEventNotifier())