一个kafka消费者组监控cli。
klag的Python项目详细描述
Klag
用于检查Kafka使用者组偏移量的命令行界面 存储在代理上(kafka 0.8.2+)。
功能
- 发现并显示所有活动的或特定的消费者组,以及 话题。
- 查看分区开始和结束的偏移量、使用者偏移量和 剩余信息。
- 以多种格式输出(human、json、离散json记录 索引/监视)。
- 以指定的间隔内置轮询。
安装
pip install klag
或
python setup.py install
示例
usage: klag [-h] [-b LIST] [-g JSON] [--groups-file FILE] [-d] [-c] [-p] [-s N] [-o FILE] [-f FORMAT] [--log-level LEVEL] [--version] Kafka 0.8.2+ consumer monitoring. optional arguments: -h, --help show this help message and exit -b LIST, --brokers LIST Comma separated list of Kafka brokers -g JSON, --groups JSON Consumer groups and list of topics for each group to check (even if dead). JSON structured as '{"<group_id>":["<topic>"]}' --groups-file FILE JSON file containing consumer groups and list of topics for each group to check (even if dead). JSON structured as '{"<group_id>":["<topic>"]}' -d, --discover Include all active consumer groups and topics in output -c, --cache Consumer groups that go dead (all consumers disconnect) will continue to be checked. Used with '-s' -p, --partitions Include partition metrics in output -s N, --seconds N Repeat check every N seconds -o FILE, --output-file FILE Write output to a file -f FORMAT, --format FORMAT Write output using the specified format structure {default,json,json-pretty,json-discrete} --log-level LEVEL Set the application logging level --version show program's version number and exit
要查看所有连接的消费者组及其主题,只需运行 klag命令。它将尝试连接到 localhost:9092作为默认值。
$ klag
如果代理不是本地代理,请指定--brokers标志。
$ klag -b <remote-broker> Group Topic Remaining ================================================================================ my-group [STABLE] topic-1 21 topic-2 15
若要查看有关单个主题分区使用情况的数据,请添加 --partitions标志。
$ klag -p Group Topic Partition Earliest Consumed Latest Remaining ================================================================================ my-group [STABLE] topic-1 21 0 52152 460290 460298 8 1 52538 460963 460968 5 2 52291 460805 460813 8 topic-2 15 0 0 187180 187182 2 1 0 187979 187984 5 2 0 187026 187034 8
要关注特定的消费者群体和主题,请使用--groups 参数。
$ klag -g '{"my-group":["topic-2"]}' Group Topic Remaining ================================================================================ my-group [STABLE] topic-2 15
要以机器可读性更强的格式输出信息,请使用 --format参数。这是为 监控系统。
$ klag -g '{"my-group":["topic-2"]}' -f json-discrete {"consumer_lag": 15, "group": "my-group", "topic": "topic-2", "state": "Stable"}
要连续运行klag,可以指定--seconds 参数,它将以指定的间隔打印使用者数据。 与--discover标志一起连续运行将 连接时添加消费者组,连接时删除 断开连接。如果你想继续关注消费者的话题 已断开连接的组,使用--cache标志启用缓存。