1、下载和导入模板zbx_zookeeper_templates.xml,模板下载地址https://github.com/flaviotorres/zabbix/tree/23b005fdff7ebe962f72559105be90e457ee20e8
2、创建zookeeper监控脚本/home/zabbix/scripts/check_zookeeper_trapper.sh,脚本内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#!/usr/bin/env bash # grab , print and send zookeeper monitoring values to zabbix via zabbix_sender # ZooKeeper Commands: The Four Letter Words in: http://zookeeper.apache.org/doc/r3.4.6/zookeeperAdmin.html # Flavio Torres, ftorres_ig.com.br # Mar, 2014 # v1, beta TMPFILE=`mktemp --suffix=-zookeeper-monitoring` TMPFILE2=`mktemp --suffix=-zookeeper-monitoring` ZABBIX=$( awk -F= '/^ServerActive/ { print $2 } ' /usr/local/zabbix/etc/zabbix_agentd .conf)
trap "rm -f $TMPFILE; rm -f $TMPFILE2 ; exit" SIGHUP SIGINT SIGTERM EXIT
echo "mntr" | curl -s telnet: //localhost :2181 > $TMPFILE
RUNNING_OK=$( echo "ruok" | curl -s telnet: //localhost :2181)
if [ $RUNNING_OK = 'imok' ]; then
echo "zk_running_ok 0" >> $TMPFILE
else # NOK or with no response
echo "zk_running_ok 1" >> $TMPFILE
fi IFS=$ '\n'
for d in ` cat $TMPFILE`
do echo "192.168.1.32 $d" >> $TMPFILE2
done IFS= ""
/usr/local/zabbix/bin/zabbix_sender -z $ZABBIX -i $TMPFILE2
rm -f $TMPFILE ; rm -f $TMPFILE2
|
注意:需要把192.168.1.32改成相应主机的IP
3、修改zabbix agent配置文件
UnsafeUserParameters=1
UserParameter=zookeeper_collect,(/home/zabbix/scripts/check_zookeeper_trapper.sh > /dev/null; echo $?)
4、重启zabbix agent
5、将主机和模板关联起来
本文转自1321385590 51CTO博客,原文链接:http://blog.51cto.com/linux10000/2069917,如需转载请自行联系原作者