11
votes

I was looking a while and didn't seem to find the answer. I'm using Spring boot 2, Spring Kafka 2.1.4 and I want to see the kafka consumer metrics in the /metrics endpoint of spring boot actuator. What I don't understand is - should I implenemt the exposure myself or is this comes out-of-box in boot 2 ?

If I to implement this my self, what is the best way to do it?

3
Kafka exposes almost the same metrics through JMX, so I suggest you to create a custom MeterBinder to expose these metrics. Plus, you can create spring boot autoconfigure and starter modules to simplify the usage. You can find an example (ready to use) here: github.com/luiztoscano/spring-boot-kmetrics Hope it helps.Luiz Toscano

3 Answers

5
votes

Targeted for micrometer v1.1.0 is the KafkaConsumerMetrics implementation of MeterBinder. This should expose the kafka consumer metrics you're looking for.

Source Reference:

https://github.com/micrometer-metrics/micrometer/blob/master/micrometer-core/src/main/java/io/micrometer/core/instrument/binder/kafka/KafkaConsumerMetrics.java

2
votes

add this config works for me:

spring.jmx.enabled=true
1
votes

You are right, there is no out-of-the-box one. You don't have choice unless to implement your own MeterBinder. For the Apache Kafka Consumer metrics per se, you should inject a KafkaListenerEndpointRegistry and call its getListenerContainers() and use their metrics() to bind to the provided MeterRegistry.

When you come up with something, feel free to contribute the solution back to Spring Boot.