How to expose kafka metrics to /actuator/metrics with spring boot 2
Solution 1
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:
Solution 2
add this config works for me:
spring.jmx.enabled=true
Solution 3
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.
Related videos on Youtube
Michael Azimov
Updated on June 04, 2022Comments
-
Michael Azimov almost 2 years
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?
-
Michael Azimov about 6 yearsThe problem seems to be that there is no elegant way to migrate the KafkaMetric objects to Micrometer metrics. The only way I see is looping all kafka metrics and creating Micrometer identical metric for each of them
-
Vassilis over 5 yearsIs there an equivalent KafkaProducerMetrics available?
-
Anakin001 over 3 yearsThis might be the correct answer for the time of writing this. It worked for me.