Send Apache Camel Actuator Metrics to Prometheus

Viewed 6207

I am trying to forward/add the Actuator Camel metrics from /actuator/camelroutes (route metrics like number of exchanges/transactions) to the Prometheus Actuator endpoint. Is there a way for me to configure Camel to add those metrics to the PrometheusMeterRegistry?

I have tried adding:

camel.component.metrics.metric-registry=io.micrometer.prometheus.PrometheusMeterRegistry

in my application.properties according to the documentation here: https://camel.apache.org/components/latest/metrics-component.html

But still nothing relating to Apache Camel is displayed in actuator/prometheus

Here are the dependencies I am using with Spring Boot 2.1.9 and Apache Camel 2.24.2:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
        <groupId>org.apache.camel</groupId>
            <artifactId>camel-metrics-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>
3 Answers

Got the Camel Routes metrics working in the /actuator/prometheus endpoint.

Use the camel-micrometer-starter dependency as stated by @claus-ibsen 's comment.

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-metrics-starter</artifactId>
        </dependency>

Set the following in your properties file:

camel.component.metrics.metric-registry=prometheusMeterRegistry

Then add set the Camel Context to use the MicrometerRouterPolicyFactory and MicrometerMessageHistoryFactory. Code seen below is places in a Configuration class:

@Configuration
public class AppConfig {

    @Bean
    public CamelContextConfiguration camelContextConfiguration() {

        return new CamelContextConfiguration() {
            @Override
            public void beforeApplicationStart(CamelContext camelContext) {
                camelContext.addRoutePolicyFactory(new MicrometerRoutePolicyFactory());
                camelContext.setMessageHistoryFactory(new MicrometerMessageHistoryFactory());
            }

            @Override
            public void afterApplicationStart(CamelContext camelContext) {

            }
        };
    }

}

You need to trigger an exchange in a route for the metrics to appear in /actuator/prometheus.

Here are the metrics made available to Prometheus:

  1. CamelMessageHistory_seconds_count
  2. CamelMessageHistory_seconds_max
  3. CamelRoutePolicy_seconds_max
  4. CamelRoutePolicy_seconds_count
  5. CamelRoutePolicy_seconds_sum

You can use the JMX Exporter jar for Prometheus to get the more detailed metrics from the JMX of Camel. I wanted to avoid this approach as it would mean that for each Camel Spring Boot App I have would use 2 ports; 1 for the JMX Metrics and 1 for the Actuator Metrics.

I can see the metrics by keeping these dependencies intact

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-management</artifactId>
</dependency>
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-metrics</artifactId>
</dependency>
<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-micrometer-starter</artifactId>
</dependency>
<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

Why dont I see the actual process and bean names rather than like process3, bean1 etc ??

    CamelMessageHistory_seconds_sum{camelContext="AppName",nodeId="process3",routeId="AppNameRoute",serviceName="MicrometerMessageHistoryService",} 0.041466
    CamelMessageHistory_seconds_count{camelContext="AppName",nodeId="bean1",routeId="AppNameRoute",serviceName="MicrometerMessageHistoryService",} 100.0
    CamelMessageHistory_seconds_sum{camelContext="AppName",nodeId="bean1",routeId="AppNameRoute",serviceName="MicrometerMessageHistoryService",} 4.8417576
Related