spring-bootprometheusspring-kafkaspring-jmxjmx-exporter

How to expose Kafka metrics from SpringBoot application through JMX to Prometheus?


I have a springboot app from which i would like to expose the kafka.consumer metrics to Prometheus via JMX. I can see the metrics here but i just don't know where to set those mBeans(i.e. kafka.consumer:type=consumer-metrics,client-id=([-.\w]+)). I understood reading the spring boot documentation that i need to activate JMX only by doing this setting spring.jmx.enabled=true but i don't know what to do extra to expose those metrics to Prometheus through JMX.


Solution

  • Kafka automatically registers its own MBeans with those names.

    enter image description here

    If you add the actuator starter, Boot will configure Micrometer to scrape those MBeans.

    However, Micrometer has deprecated the JMX scraper and has new KafkaMetrics Objects.

    Spring Boot 2.3 now uses those classes to configure Micrometer instead of JMX.