Send Apache Camel Actuator Metrics to Prometheus

旧时模样 提交于 2021-01-21 10:38:04

问题


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>

回答1:


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.




回答2:


There is a camel-micrometer-starter dependency you should use instead that integrates with micrometer. And then you can use the micrometer route policy from that dependency to let it monitor all your routes. See the docs at: https://camel.apache.org/components/2.x/micrometer-component.html



来源:https://stackoverflow.com/questions/58536192/send-apache-camel-actuator-metrics-to-prometheus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!