在 Spring Boot Camel 应用程序公开的 Micrometer / Prometheus 信息中包含其他 JMX 指标

问题描述

我已经使用 Camel 3.9 配置了一个 Spring Boot 2 应用程序,以使用 Micrometer 通过 actuator/prometheus 端点公开指标,正确返回一些 Camel 指标:

# HELP CamelExchangesFailed_total  
# TYPE CamelExchangesFailed_total counter
CamelExchangesFailed_total{camelContext="camel-1",routeId="route3",serviceName="MicrometerRoutePolicyService",} 0.0
CamelExchangesFailed_total{camelContext="camel-1",routeId="route2",routeId="route1",} 0.0
# HELP CamelExchangesTotal_total  
# TYPE CamelExchangesTotal_total counter
CamelExchangesTotal_total{camelContext="camel-1",} 0.0
CamelExchangesTotal_total{camelContext="camel-1",} 0.0
# HELP CamelExchangesExternalRedeliveries_total  
# TYPE CamelExchangesExternalRedeliveries_total counter
CamelExchangesExternalRedeliveries_total{camelContext="camel-1",} 0.0
CamelExchangesExternalRedeliveries_total{camelContext="camel-1",} 0.0
# HELP CamelExchangesSucceeded_total  
# TYPE CamelExchangesSucceeded_total counter
CamelExchangesSucceeded_total{camelContext="camel-1",} 0.0
CamelExchangesSucceeded_total{camelContext="camel-1",} 0.0
# HELP CamelExchangesFailuresHandled_total  
# TYPE CamelExchangesFailuresHandled_total counter
CamelExchangesFailuresHandled_total{camelContext="camel-1",} 0.0
CamelExchangesFailuresHandled_total{camelContext="camel-1",} 0.0

探索 mbeans,我可以看到还有一些我也感兴趣的其他指标(例如路由平均处理时间)

enter image description here

问题是,我怎样才能让 Spring Boot Actuator + Micrometer + Prometheus 包含这些额外的指标?

following article 描述了一种使用 JMX 代理通过 config.yml 文件在 Prometheus 上发布的方法:

src/main/resources/config.yml

rules:
  - pattern: 'fis.metrics<name=os.(.*)><>(.+):'
    name: os_$1
    help: some help

  - pattern: 'org.apache.camel<context=camel,type=routes,name=\"(.*)\"><>LastProcessingTime'
    name: camel_last_processing_time
    help: Last Processing Time [milliseconds]
    type: GAUGE
    labels:
      route: $1

但是,我无法找到使用 Spring Boot Actuator + Micrometer/Prometheus 的当前基础架构来做到这一点的方法。

这是我的配置:

依赖:

plugins {
    id "org.springframework.boot" version "2.4.4"
    id "com.github.lkishalmi.gatling" version "3.3.4"
}

apply plugin: 'eclipse'
apply plugin: 'com.github.lkishalmi.gatling'

description = """sle-sync"""

ext {
    springCloudVersion = '2020.0.2'
    orikaVersion = '1.5.2'
    junitVersion = '5.2.0'
    junitPlatformVersion = '1.2.0'
    camelVersion = '3.9.0'
}

repositories {
    mavenLocal()
}

dependencyManagement {
    imports {
        mavenBom "org.apache.camel.springboot:camel-spring-boot-bom:${camelVersion}"
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

dependencies {
    implementation 'org.apache.camel.springboot:camel-spring-boot-starter','org.apache.camel.springboot:camel-servlet-starter','org.apache.camel.springboot:camel-http-starter','org.apache.camel.springboot:camel-metrics-starter',"org.apache.camel.springboot:camel-micrometer-starter",'com.playtika.sleuth:sleuth-camel-core:2.1.0',"org.springframework.boot:spring-boot-starter-web","org.springframework.boot:spring-boot-starter-actuator","org.springframework.cloud:spring-cloud-starter-config","org.springframework.cloud:spring-cloud-starter-kubernetes-fabric8-config","org.springframework.cloud:spring-cloud-starter-sleuth","io.micrometer:micrometer-registry-prometheus","ma.glasnost.orika:orika-core:${orikaVersion}",'org.projectlombok:lombok',"jakarta.xml.bind:jakarta.xml.bind-api:2.3.2","org.glassfish.jaxb:jaxb-runtime:2.3.2",'org.apache.camel:camel-management'
    testCompile 'org.apache.camel:camel-test-spring',"org.springframework.boot:spring-boot-starter-test",'com.github.sbrannen:spring-test-junit5:1.0.2',"org.junit.jupiter:junit-jupiter-api:${junitVersion}"
    testRuntimeOnly "org.junit.platform:junit-platform-launcher:${junitPlatformVersion}","org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
    annotationProcessor "org.projectlombok:lombok:1.18.10"
    testAnnotationProcessor "org.projectlombok:lombok:1.18.10"
}

骆驼上下文配置:


    @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) {

            }
        };
    }

应用程序.yml

camel:
  component:
    servlet:
      mapping:
        context-path: /api/*
    metrics:

      metric-registry: prometheusMeterRegistry


management:
  endpoints:
    web:
      exposure:
        include: info,health,prometheus

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)