title: How can I list the Kafka consumer lag and latest offset per partition and consumer group using the Kafka .NET client API?
body: <p>I'm trying to get the consumer lag using the .NET Confluent.Kafka 1.4.0-RC1 (for Net472). 
  I can get the desired result using this script: </p>
  
  <pre><code>$ bin/kafka-run-class.sh kafka.admin.ConsumerGroupCommand --bootstrap-server localhost:9092 --group Grp1 --describe
  </code></pre>
  
  <p>Resulting:</p>
  
  <pre><code>GROUP           TOPIC           PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG             CONSUMER-ID                                  HOST            CLIENT-ID
  Grp1            test3           1          15              15              0               rdkafka-ca76855f-7b66-4bf1-82bc-73e9a1c1cf71 /10.186.129.93  rdkafka
  Grp1            test3           2          13              13              0               rdkafka-d64379dc-881a-4f6f-a793-51e832cc2f5a /10.186.129.93  rdkafka
  Grp1            test3           0          9               9               0               rdkafka-a25bdb80-3b70-4e42-963e-d41ad9e2a99a /10.186.129.93  rdkafka
  Grp1            test            0          68              68              0               -                                            -               -
  </code></pre>
  
  <p>I'm not able to get similar report using the .NET client code. Here's the code I've been trying - but getting nothing as the <code>consumer.Assignment</code> property has an empty collection. </p>
  
  <pre><code>private string WriteConsumerGroupLags(string bootstrapServers, string consumerGroupName) {
      // kafka-console-consumer.bat --zookeeper MW45670117:2380 --topic powertelemetry --consumer-property group.id=test123 --consumer-property enable.auto.commit=true
  
      StringBuilder sb = new StringBuilder();
      sb.AppendLine("\n");
      sb.AppendLine("Consumer Group Lag Report");
      sb.AppendLine("-------------------------");
      ConsumerConfig config = new ConsumerConfig {
          BootstrapServers = bootstrapServers,
          GroupId = consumerGroupName,
          AutoOffsetReset = AutoOffsetReset.Earliest
      };
  
      using (var consumer = new ConsumerBuilder&lt;Ignore, string&gt;(config).Build()) {
          foreach (TopicPartition tp in consumer.Assignment) {
              string topic = tp.Topic;
              int partitionID = tp.Partition.Value;
              // gets the current position (offset) for the specific topic/partition
              Offset offset = consumer.Position(new TopicPartition(topic, new Partition(partitionID)));
              sb.AppendLine($"Offset value is: {offset.Value}");
  
              // returns current commited offset for the current assignment
              List&lt;TopicPartitionOffset&gt; tpos = consumer.Committed(TimeSpan.FromSeconds(4));
              foreach (TopicPartitionOffset tpo in tpos) {
                  sb.AppendLine($"Commited offset for partition {tpo.TopicPartition} is {tpo.Offset}");
              }
          }
      }
  
      return sb.ToString();
  }
  </code></pre>
  
  <p>Looking for both consumer lag and latest offset per partition/consumer-group. </p>