问题:
prometheus监控kafka的插件kafka_exporter启动日志报错如下
time="2020-12-11T08:41:08+08:00" level=error msg="Cannot get leader of topic input_topic partition 1: kafka server: In the middle of a leadership election, there is currently no leader for this partition and hence it is unavailable for writes." source="kafka_exporter.go:275"
time="2020-12-11T08:41:08+08:00" level=error msg="Cannot get leader of topic input_topic partition 1: kafka server: In the middle of a leadership election, there is currently no leader for this partition and hence it is unavailable for writes." source="kafka_exporter.go:275"
time="2020-12-11T08:41:08+08:00" level=error msg="Cannot get leader of topic input_topic partition 1: kafka server: In the middle of a leadership election, there is currently no leader for this partition and hence it is unavailable for writes." source="kafka_exporter.go:275"
time="2020-12-11T08:41:08+08:00" level=error msg="Cannot get leader of topic input_topic partition 1: kafka server: In the middle of a leadership election, there is currently no leader for this partition and hence it is unavailable for writes." source="kafka_exporter.go:275"
time="2020-12-11T08:42:07+08:00" level=error msg="Cannot get oldest offset of topic tb.transport.api.responses partition 1: kafka: broker not connected" source="kafka_exporter.go:296"
time="2020-12-11T08:42:07+08:00" level=error msg="Cannot get oldest offset of topic message_queue_output_dic partition 0: kafka: broker not connected" source="kafka_exporter.go:296"
time="2020-12-11T08:42:37+08:00" level=error msg="Cannot get oldest offset of topic message_queue_output_dic partition 1: kafka: broker not connected" source="kafka_exporter.go:296"
解决方法:
前提是kafka的配置文件 server.properties 必须配置如下参数:
# 启用删除主题
delete.topic.enable=true
# 检查日志段文件的间隔时间,以确定是否文件属性是否到达删除要求。
log.retention.check.interval.ms=1000
需要把如上报错的topic删除后重建即可完成:input_topic,message_queue_output_dic
将这两个topic删除后重建解决问题
1、查看topic信息
./kafka-topics.sh --describe --zookeeper 192.168.5.53:2181 --topic input_topic
Topic:input_topic PartitionCount:3 ReplicationFactor:1 Configs:
Topic: input_topic Partition: 0 Leader: 1 Replicas: 1 Isr: 1
Topic: input_topic Partition: 1 Leader: -1 Replicas: 2 Isr: 1
Topic: input_topic Partition: 2 Leader: 3 Replicas: 3 Isr: 3
2、删除topic
./kafka-topics.sh --delete --zookeeper 192.168.5.53:2181 --topic input_topic partition
3、重建topic问题报错解决
./kafka-topics.sh --create --zookeeper 192.168.5.53:2181 --topic input_topic partition --replication-factor 3 --partitions 3
topic:message_queue_output_dic 按照1-3步骤完成操作即可。