Created
August 10, 2020 10:07
-
-
Save sashomasho/b5807a7e8c6e4e38b8995f34e4b6bc4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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