title: How to monitor consumer lag in kafka via jmx?
body: <p>I have a kafka setup that includes a jmx exporter to prometheus. I'm looking for a metric, that gives the offset lag based on topic and groupid. I'm running kafka 2.2.0.</p>
  
  <p>Some resources online point to a metric called <code>kafka.consumer</code>, but I have no such metric in my setup.</p>
  
  <p>From my jmxterminal:</p>
  
  <pre class="lang-sh prettyprint-override"><code>$&gt;domains
  #following domains are available
  JMImplementation
  com.sun.management
  java.lang
  java.nio
  java.util.logging
  jdk.management.jfr
  kafka
  kafka.cluster
  kafka.controller
  kafka.coordinator.group
  kafka.coordinator.transaction
  kafka.log
  kafka.network
  kafka.server
  kafka.utils
  </code></pre>
  
  <p>I am, however, able to see the data I need by using the following command:</p>
  
  <pre class="lang-sh prettyprint-override"><code>root@kafka-0:/kafka# bin/kafka-consumer-groups.sh --describe --group benchmark_consumer_group --bootstrap-server localhost:9092
  Consumer group 'benchmark_consumer_group' has no active members.
  
  TOPIC               PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG             CONSUMER-ID     HOST            CLIENT-ID
  benchmark_topic_10B 2          2795128         54223220        51428092        -               -               -
  benchmark_topic_10B 9          4               4               0               -               -               -
  benchmark_topic_10B 6          7               7               0               -               -               -
  benchmark_topic_10B 7          5               5               0               -               -               -
  benchmark_topic_10B 0          2834028         54224939        51390911        -               -               -
  benchmark_topic_10B 1          15342331        54222342        38880011        -               -               -
  benchmark_topic_10B 4          5               5               0               -               -               -
  benchmark_topic_10B 5          6               6               0               -               -               -
  benchmark_topic_10B 8          8               8               0               -               -               -
  benchmark_topic_10B 3          4               4               0               -               -               -
  
  
  </code></pre>
  
  <p>But that does not help since I need to track if from a metric. Also, this command takes about 25 seconds to execute, making it unreasonable to use as a source for metrics.</p>
  
  <p>My guess is that the metric <code>kafka.consumer</code> does not exist in version 2.2.0 and was replaced with another. Although, I can't find any resources online with up-to-date information on how and where to get that metric</p>