question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get Consumer lag using LibrdkafkaHandle.OutQueueLength

See original GitHub issue

Description

Hi!

I found a way to get a consumer’s topic lag by reading the internal property OutQueueLength found in the internal LibrdkafkaHandle Handle property of the consumer. Is this a “safe” hack? @mhowlett, can you please explain me why this property was not publicly exposed in the library? If this version is not safe is there another way to accomplish this? Thank you, Alex

Code:

var propertyLevel1 = _consumer.Handle.GetType().GetProperty("LibrdkafkaHandle", BindingFlags.NonPublic | BindingFlags.Instance);
var valueLevel1 = propertyLevel1.GetValue(_consumer.Handle);

var propertyLevel2 = valueLevel1.GetType().GetProperty("OutQueueLength", BindingFlags.NonPublic | BindingFlags.Instance);
var valueLevel2 = propertyLevel2.GetValue(valueLevel1);
                        
topicLag = Convert.ToInt64(valueLevel2);

Checklist

Please provide the following information:

  • A complete (i.e. we can run it), minimal program demonstrating the problem. No need to supply a project file.
  • Confluent.Kafka nuget version: 1.3.0
  • Apache Kafka version: 2.x
  • Client configuration.
  • Operating system : Linux
  • Provide logs (with “debug” : “…” as necessary in configuration).
  • Provide broker log excerpts.
  • Critical issue.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
alexandrutatagitcommented, Jan 16, 2020

Thank you @edenhill ! Can you please tell me how I can do this in the C# library? Should I hack the same way I did above?

0reactions
dogac00commented, Apr 24, 2021

@wxlevel You have to Subscribe to your topic for consumer to be assigned to partitions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Consumergroup lag statistics · Issue #1822
The consumer lag is only calculated when partitions have been assigned and are fetched. When you use the high-level balanced consumer (-G) it ......
Read more >
Untitled
Check lag kafka Check all the lags in Kafka - Stack Overflow Get comprehensive ... You can use kafka-consumer-groups.sh command to find out...
Read more >
Monitoring the Kafka consumer lag
An efficient streaming application requires consumer lag to be minimal, a higher consumer lag indicates performance problems with the consumers.
Read more >
Monitor Consumer Lag in Confluent Cloud
Monitor Consumer Latency via Client Interceptors​​ You can use Confluent Control Center to track consumer latency and more.
Read more >
Monitor the Consumer Lag in Apache Kafka
Kafka consumer group lag is a key performance indicator of any Kafka-based event-driven system. In this tutorial, we'll build an analyzer ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found