将 Apache Camel 执行器指标发送到 Prometheus

Send Apache Camel Actuator Metrics to Prometheus

我正在尝试 forward/add 来自 /actuator/camelroutes 的 Actuator Camel 指标(路由指标,例如 exchanges/transactions 的数量)到 Prometheus Actuator 端点。有没有办法让我配置 Camel 以将这些指标添加到 PrometheusMeterRegistry?

我试过添加:

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

根据此处的文档,在我的 application.properties 中:https://camel.apache.org/components/latest/metrics-component.html

但是 actuator/prometheus

中仍然没有显示任何与 Apache Camel 相关的内容

这是我在 Spring Boot 2.1.9Apache 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>

您应该使用 camel-micrometer-starter 与千分尺集成的依赖项。然后您可以使用该依赖项中的千分尺路由策略,让它监控您的所有路由。请参阅文档:https://camel.apache.org/components/2.x/micrometer-component.html

让 Camel Routes 指标在 /actuator/prometheus 端点工作。

使用 camel-micrometer-starter 依赖项,如@claus-ibsen 的评论所述。

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

在您的属性文件中设置以下内容:

camel.component.metrics.metric-registry=prometheusMeterRegistry

然后添加设置 Camel 上下文以使用 MicrometerRouterPolicyFactory 和 MicrometerMessageHistoryFactory。下面看到的代码位于配置 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) {

            }
        };
    }

}

您需要在路由中触发交换,指标才会出现在 /actuator/prometheus

以下是 Prometheus 可用的指标:

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

您可以使用 Prometheus 的 JMX Exporter jar 从 Camel 的 JMX 中获取更详细的指标。我想避免这种方法,因为这意味着对于每个 Camel Spring 我有的启动应用程序会使用 2 个端口; 1 个用于 JMX 指标,1 个用于执行器指标。

我可以通过保持这些依赖关系不变来查看指标

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

为什么我看不到实际的进程和 bean 名称,而不是 process3、bean1 等??

    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