title: Include additional JMX metrics in Micrometer / Prometheus info exposed by a Spring Boot Camel application
body: <p>I've configured a Spring Boot 2 application with Camel 3.9 to expose metrics, using Micrometer, through the <code>actuator/prometheus</code> endpoint, returning some Camel metrics correctly:</p>
  <pre><code># HELP CamelExchangesFailed_total  
  # TYPE CamelExchangesFailed_total counter
  CamelExchangesFailed_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route3&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  CamelExchangesFailed_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route2&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  CamelExchangesFailed_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route1&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  # HELP CamelExchangesTotal_total  
  # TYPE CamelExchangesTotal_total counter
  CamelExchangesTotal_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route3&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  CamelExchangesTotal_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route2&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  CamelExchangesTotal_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route1&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  # HELP CamelExchangesExternalRedeliveries_total  
  # TYPE CamelExchangesExternalRedeliveries_total counter
  CamelExchangesExternalRedeliveries_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route3&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  CamelExchangesExternalRedeliveries_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route2&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  CamelExchangesExternalRedeliveries_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route1&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  # HELP CamelExchangesSucceeded_total  
  # TYPE CamelExchangesSucceeded_total counter
  CamelExchangesSucceeded_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route3&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  CamelExchangesSucceeded_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route2&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  CamelExchangesSucceeded_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route1&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  # HELP CamelExchangesFailuresHandled_total  
  # TYPE CamelExchangesFailuresHandled_total counter
  CamelExchangesFailuresHandled_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route3&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  CamelExchangesFailuresHandled_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route2&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  CamelExchangesFailuresHandled_total{camelContext=&quot;camel-1&quot;,routeId=&quot;route1&quot;,serviceName=&quot;MicrometerRoutePolicyService&quot;,} 0.0
  </code></pre>
  <p>Exploring the mbeans, I can see there are some other metrics I am also interested (e.g. route mean processing time)</p>
  <p><a href="https://i.stack.imgur.com/90Fq5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/90Fq5.png" alt="enter image description here" /></a></p>
  <p>The question is, how can I make Spring Boot Actuator + Micrometer + Prometheus include those additional metrics?</p>
  <p>The <a href="https://brunonetid.github.io/2017/11/27/camel-prometheus-openshift.html" rel="nofollow noreferrer">following article</a> describes a way to use a JMX agent to publish on Prometheus using a config.yml file:</p>
  <pre><code>src/main/resources/config.yml
  
  rules:
    - pattern: 'fis.metrics&lt;name=os.(.*)&gt;&lt;&gt;(.+):'
      name: os_$1
      help: some help
  
    - pattern: 'org.apache.camel&lt;context=camel, type=routes, name=\&quot;(.*)\&quot;&gt;&lt;&gt;LastProcessingTime'
      name: camel_last_processing_time
      help: Last Processing Time [milliseconds]
      type: GAUGE
      labels:
        route: $1
  </code></pre>
  <p>However I can't find a way to do it with the current infrastructure of Spring Boot Actuator + Micrometer/Prometheus.</p>
  <p>This is my config:</p>
  <p>Dependencies:</p>
  <pre><code>plugins {
      id &quot;org.springframework.boot&quot; version &quot;2.4.4&quot;
      id &quot;com.github.lkishalmi.gatling&quot; version &quot;3.3.4&quot;
  }
  
  apply plugin: 'eclipse'
  apply plugin: 'com.github.lkishalmi.gatling'
  
  description = &quot;&quot;&quot;sle-sync&quot;&quot;&quot;
  
  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 &quot;org.apache.camel.springboot:camel-spring-boot-bom:${camelVersion}&quot;
          mavenBom &quot;org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}&quot;
      }
  }
  
  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',
              &quot;org.apache.camel.springboot:camel-micrometer-starter&quot;,
              'com.playtika.sleuth:sleuth-camel-core:2.1.0',
              &quot;org.springframework.boot:spring-boot-starter-web&quot;,
              &quot;org.springframework.boot:spring-boot-starter-actuator&quot;,
              &quot;org.springframework.cloud:spring-cloud-starter-config&quot;,
              &quot;org.springframework.cloud:spring-cloud-starter-kubernetes-fabric8-config&quot;,
              &quot;org.springframework.cloud:spring-cloud-starter-sleuth&quot;,
              &quot;io.micrometer:micrometer-registry-prometheus&quot;,
              &quot;ma.glasnost.orika:orika-core:${orikaVersion}&quot;,
              'org.projectlombok:lombok',
              &quot;jakarta.xml.bind:jakarta.xml.bind-api:2.3.2&quot;,
              &quot;org.glassfish.jaxb:jaxb-runtime:2.3.2&quot;,
              'org.apache.camel:camel-management'
      testCompile 'org.apache.camel:camel-test-spring',
              &quot;org.springframework.boot:spring-boot-starter-test&quot;,
              'com.github.sbrannen:spring-test-junit5:1.0.2',
              &quot;org.junit.jupiter:junit-jupiter-api:${junitVersion}&quot;
      testRuntimeOnly &quot;org.junit.platform:junit-platform-launcher:${junitPlatformVersion}&quot;,
              &quot;org.junit.jupiter:junit-jupiter-engine:${junitVersion}&quot;
      annotationProcessor &quot;org.projectlombok:lombok:1.18.10&quot;
      testAnnotationProcessor &quot;org.projectlombok:lombok:1.18.10&quot;
  }
  
  </code></pre>
  <p>CamelContextConfiguration:</p>
  <pre><code>
      @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) {
  
              }
          };
      }
  </code></pre>
  <p>application.yml</p>
  <pre><code>camel:
    component:
      servlet:
        mapping:
          context-path: /api/*
      metrics:
  
        metric-registry: prometheusMeterRegistry
  
  
  management:
    endpoints:
      web:
        exposure:
          include: info, health, prometheus
  </code></pre>