为什么 CamelExchangesFailed_total 指标没有增加?

Why is CamelExchangesFailed_total metrics not increased?

我有一个由 Prometheus 监控的 Apache Camel 应用程序。因此,我将 Micrometer 添加到我的 POM(参见 Spring Boot Auto-Configuration) and MicrometerRoutePolicyFactory to my application (see Using Micrometer Route Policy Factory)。但是指标 CamelExchangesFailed_total 没有改变,尽管路由失败了。

来源

@SpringBootApplication
public class TestApplication {

  public static void main(String[] args) {
    SpringApplication.run(TestApplication.class, args);
  }

  @Bean
  public MicrometerRoutePolicyFactory micrometerRoutePolicyFactory() {
    return new MicrometerRoutePolicyFactory();
  }

  @Bean
  public EndpointRouteBuilder route() {
    return new EndpointRouteBuilder() {
      @Override
      public void configure() throws Exception {
        errorHandler(deadLetterChannel("log:dead"));
        from(timer("testTimer").repeatCount(1)).throwException(new RuntimeException());
      }
    };
  }
}

日志

INFO 5060 --- [  restartedMain] o.a.c.i.e.InternalRouteStartupManager    : Route: route1 started and consuming from: timer://testTimer
INFO 5060 --- [  restartedMain] o.a.c.impl.engine.AbstractCamelContext   : Total 1 routes, of which 1 are started
INFO 5060 --- [  restartedMain] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 3.5.0 (camel-1) started in 0.007 seconds
INFO 5060 --- [  restartedMain] test.TestApplication   : Started TestApplication in 6.626 seconds (JVM running for 7.503)
INFO 5060 --- [on(3)-127.0.0.1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
INFO 5060 --- [on(3)-127.0.0.1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
INFO 5060 --- [on(3)-127.0.0.1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 5 ms
INFO 5060 --- [mer://testTimer] dead                                     : Exchange[ExchangePattern: InOnly, BodyType: null, Body: [Body is null]]

指标

# HELP CamelExchangesFailed_total  
# TYPE CamelExchangesFailed_total counter
CamelExchangesFailed_total{application="test",camelContext="camel-1",routeId="route1",serviceName="MicrometerRoutePolicyService",} 0.0
# HELP CamelExchangesSucceeded_total  
# TYPE CamelExchangesSucceeded_total counter
CamelExchangesSucceeded_total{application="test",camelContext="camel-1",routeId="route1",serviceName="MicrometerRoutePolicyService",} 1.0

研究

问题

为什么 CamelExchangesFailed_total 指标没有增加?有什么方法可以使用自定义错误处理程序来计算所有失败的路由吗?

A​​pache Camel LTS 版本 3.7.0 added a new metric CamelExchangesFailuresHandled_total, which is a counter of handled errors, see CAMEL-15908:

Similar to CAMEL-15255, there are some additional counter metrics we could add to the MicrometerRoutePolicy for:

  • Total exchanges processed
  • Number of failures handled
  • Number of external redeliveries

指标

# HELP CamelExchangesFailed_total  
# TYPE CamelExchangesFailed_total counter
CamelExchangesFailed_total{application="test",camelContext="camel-1",routeId="route1",serviceName="MicrometerRoutePolicyService",} 0.0
# HELP CamelExchangesSucceeded_total  
# TYPE CamelExchangesSucceeded_total counter
CamelExchangesSucceeded_total{application="test",camelContext="camel-1",routeId="route1",serviceName="MicrometerRoutePolicyService",} 1.0
# HELP CamelExchangesFailuresHandled_total  
# TYPE CamelExchangesFailuresHandled_total counter
CamelExchangesFailuresHandled_total{application="test",camelContext="camel-1",routeId="route1",serviceName="MicrometerRoutePolicyService",} 1.0