目录
正文
1、lag:多少消息没有消费 lag=logsize-offset2、logsize:Kafka存的消息总数
1、lag:多少消息没有消费 lag=
logsize-
offset
2、logsize:Kafka存的消息总数
3、offset:已经消费的消息
cat /home/app/zookeeper/zookeeper/conf/zoo.cfg | egrep -v "^$|^#" clientPort=2181
cat /home/app/kafka/kafka/config/server.properties | egrep -v "^$|^#" port=9092 host.name=192.168.0.11 zookeeper.connect=192.168.0.11:2181,192.168.0.12:2181,192.168.0.13:2181
cd /home/app/zookeeper/zookeeper/bin ./zkCli.sh -server 192.168.0.11:2181 ls /consumers/ lijieGroup quit
/home/app/kafka/kafka/bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --group=lijieGroup --zookeeper=192.168.0.11:2181
因为zabbix用户不能调用kafka的脚本,需要root用户启动zabbix_agent
vim /opt/zabbix/zabbix_agentd.conf AllowRoot=1 User=root Include=/opt/zabbix/zabbix_agentd.conf.d/ vim /opt/zabbix/zabbix_agentd.conf.d/kafka_status.conf UserParameter=kafka.lag[*],/home/zabbix_scripts/kafka_mon.sh $1 $2 lag UserParameter=kafka.offset[*],/home/zabbix_scripts/kafka_mon.sh $1 $2 offset UserParameter=kafka.logsize[*],/home/zabbix_scripts/kafka_mon.sh $1 $2 logsize chown -R zabbix:zabbix /opt/zabbix/zabbix_agentd.conf.d/kafka_status.conf chmod -R 777 /opt/zabbix/zabbix_agentd.conf.d/kafka_status.conf
mkdir -pv /home/zabbix_scripts/ vim /home/zabbix_scripts/kafka_mon.sh
#!/bin/bash
kafka_ip=
"127.0.0.1"
kafka_port=2181
topic_name=$1
group_id=$2
pn=$3
/usr/local/kafka_2
.11-0.11.0.0
/bin/kafka-run-class
.sh kafka.tools.ConsumerOffsetChecker --topic=$topic_name --group=$group_id --zookeeper=$kafka_ip:$kafka_port |
grep
-
v
Offset >
/tmp/kafka-tp-
${topic_name}-${group_id}.info
Offset=0
logSize=0
Lag=0
while
read
line
do
Offset=$((${Offset}+`
echo
$line |
awk
'{print $4}'
`))
logSize=$((${logSize}+`
'{print $5}'
Lag=$(($Lag+`
'{print $6}'
done
<
case
$pn
in
offset|Offset)
$Offset
;;
logsize|logSize)
$logSize
;; lag|Lag)
$Lag
*)
Error
esac
chown -R zabbix:zabbix /home/zabbix_scripts/kafka_mon.sh chmod -R 777 /home/zabbix_scripts/kafka_mon.sh touch /tmp/kafka-tp-RouterOnOfflineStateChange-lijieGroup.info chmod 777 /tmp/kafka-tp-RouterOnOfflineStateChange-lijieGroup.info chown zabbix:zabbix /tmp/kafka-tp-RouterOnOfflineStateChange-lijieGroup.info chmod 777 /home/app/kafka/kafka/bin/kafka-run-class.sh
/etc/init.d/zabbix-agent restart
kafka.offset[topic_data,obdGroup] kafka.logsize[topic_data,obdGroup] kafka.lag[topic_data,obdGroup]