Skip to content

Instantly share code, notes, and snippets.

@sashomasho
Created August 10, 2020 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sashomasho/b5807a7e8c6e4e38b8995f34e4b6bc4b to your computer and use it in GitHub Desktop.
Save sashomasho/b5807a7e8c6e4e38b8995f34e4b6bc4b to your computer and use it in GitHub Desktop.
import sys
import subprocess
if len(sys.argv) == 1:
print('please specify a group-id')
sys.exit(-1)
KAFKA_HOSTS="localhost:9092"
if len(sys.argv) > 2:
KAFKA_HOSTS=sys.argv[2]
consumer_group_id = sys.argv[1]
cmd = "/opt/kafka/bin/kafka-consumer-groups.sh --bootstrap-server %s --group %s --describe" % (KAFKA_HOSTS, consumer_group_id)
offset_sum = 0
lag_sum = 0
cmd_run = subprocess.run(cmd.split(), stdout=subprocess.PIPE)
for line in cmd_run.stdout.decode('utf-8').splitlines():
if line.startswith(consumer_group_id):
parts = line.split()
#print(parts)
offset_sum += int(parts[4])
lag_sum += int(parts[5])
print('current offset:', offset_sum)
print('current lag:', lag_sum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment