title: KafkaMetrics - Failed to bind meter: kafka.consumer*
body: <p>I have deployed an application as a container on OpenShift. The application consists of four threads (i.e. consumers) - each polling on a unique topic. I would like to display the KafkaMetrics for each of the consumers/topics. I have already sat up a functioning Prometheus endpoint.</p>
  <p>Each of the consumers' metrics are bound to this Prometheus Registry by:</p>
  <pre><code>KafkaClientMetrics(consumer).bindTo(promRegistry)
  </code></pre>
  <p>Moreover, I have experienced incosistency of the displayed metrics at the Prometheus endpoint. For some metrics, data is displayed for only one of the consumers. I also get the following warnings in the OpenShift log:</p>
  <pre><code>{&quot;@timestamp&quot;:&quot;2021-09-06T12:45:43.608+02:00&quot;,&quot;@version&quot;:&quot;1&quot;,&quot;message&quot;:&quot;Failed to bind meter: 
  kafka.consumer.fetch.manager.records.lag.max [tag(client.id=client2), tag(topic=my_topic), tag(partition=2), tag(kafka.version=6.2.0-ccs)].&quot;,
  &quot;logger_name&quot;:&quot;io.micrometer.core.instrument.binder.kafka.KafkaMetrics&quot;,&quot;thread_name&quot;:&quot;micrometer-kafka-metrics&quot;,&quot;level&quot;:&quot;WARN&quot;,&quot;level_value&quot;:30000,
  &quot;stack_trace&quot;:&quot;java.lang.IllegalArgumentException: Collector already registered that provides name: 
  kafka_consumer_fetch_manager_records_lag_max\n\t
  at io.prometheus.client.CollectorRegistry.register(CollectorRegistry.java:54)\n\t
  at io.prometheus.client.Collector.register(Collector.java:139)\n\t
  at io.micrometer.prometheus.PrometheusMeterRegistry.lambda$applyToCollector$16(PrometheusMeterRegistry.java:410)\n\t
  at java.base/java.util.concurrent.ConcurrentHashMap.compute(Unknown Source)\n\t
  at io.micrometer.prometheus.PrometheusMeterRegistry.applyToCollector(PrometheusMeterRegistry.java:406)\n\t
  at io.micrometer.prometheus.PrometheusMeterRegistry.newGauge(PrometheusMeterRegistry.java:208)\n\t
  at io.micrometer.core.instrument.MeterRegistry.lambda$gauge$1(MeterRegistry.java:298)\n\t
  at io.micrometer.core.instrument.MeterRegistry.lambda$registerMeterIfNecessary$5(MeterRegistry.java:562)\n\t
  at io.micrometer.core.instrument.MeterRegistry.getOrCreateMeter(MeterRegistry.java:620)\n\t
  at io.micrometer.core.instrument.MeterRegistry.registerMeterIfNecessary(MeterRegistry.java:569)\n\t
  at io.micrometer.core.instrument.MeterRegistry.registerMeterIfNecessary(MeterRegistry.java:562)\n\t
  at io.micrometer.core.instrument.MeterRegistry.gauge(MeterRegistry.java:298)\n\t
  at io.micrometer.core.instrument.Gauge$Builder.register(Gauge.java:190)\n\t
  at io.micrometer.core.instrument.binder.kafka.KafkaMetrics.registerGauge(KafkaMetrics.java:224)\n\t
  at io.micrometer.core.instrument.binder.kafka.KafkaMetrics.registerMeter(KafkaMetrics.java:216)\n\t
  at io.micrometer.core.instrument.binder.kafka.KafkaMetrics.bindMeter(KafkaMetrics.java:208)\n\
  at io.micrometer.core.instrument.binder.kafka.KafkaMetrics.lambda$checkAndBindMetrics$1(KafkaMetrics.java:191)\n\t
  at java.base/java.util.concurrent.ConcurrentHashMap.forEach(Unknown Source)\n\t
  at java.base/java.util.Collections$UnmodifiableMap.forEach(Unknown Source)\n\t
  at io.micrometer.core.instrument.binder.kafka.KafkaMetrics.checkAndBindMetrics(KafkaMetrics.java:161)\n\t
  at io.micrometer.core.instrument.binder.kafka.KafkaMetrics.lambda$bindTo$0(KafkaMetrics.java:112)\n\t
  at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)\n\t
  at java.base/java.util.concurrent.FutureTask.runAndReset(Unknown Source)\n\t
  at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)\n\t
  at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\n\t
  at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\n\t
  at java.base/java.lang.Thread.run(Unknown Source)\n&quot;}
  </code></pre>
  <p>These type warnings occur for the three conumers that does not display all the metrics.</p>
  <p>Have anyone experienced this exception before?</p>
  <p>I will happily provide more information or code if necessary, but as of now I do not know what code would be relevant to include.</p>