Zabbix监控zookeeper
近期需求增加zookeeper监控到zabbix,经过一番搜索,确定通过agentd端运行脚本的方式采集数据,传送给zabbix-server端.
Zabbix_sender方式发送
将这些监控数据一次性使用zabbix_sender全部发送给zabbix.将监控项目汇集成一个字典,然后遍历这个字典,将字典中的key:value对通过zabbix_sender的-k和-o参数指定发送出去.
感谢博文:/reblue520/article/details/52352689
基本上参考了这篇博文的方法及python脚本.模版文档.
经过修改及仔细查看, 该博文中的xml模版文件,发现 server 通过 调用zookeeper.status[alive] 这个key值,来获取pid, 同时出发sender 发送给server 数据 . 无需配合计划任务, 可能是我初学python , 没有理解好用途. 总之没成功,但是经过修改后,可以 正确获取数据.
下面为修改后的 python代码
#!/usr/bin/python"""{'zk_followers':0,'zk_outstanding_requests':0,'zk_approximate_data_size':890971,'zk_packets_sent':5818488,'zk_pending_syncs':0,'zk_avg_latency':0,'zk_version':'3.4.6-1569965,builton02/20/09:09GMT','zk_watch_count':1364,'zk_packets_received':5797681,'zk_open_file_descriptor_count':46,'zk_server_ruok':'imok','zk_server_state':'follower','zk_synced_followers':0,'zk_max_latency':400,'zk_num_alive_connections':18,'zk_min_latency':0,'zk_ephemerals_count':1112,'zk_znode_count':2207,'zk_max_file_descriptor_count':4096}"""importsysimportsocketimportreimportsubprocessfromStringIOimportStringIOimportoszabbix_sender='/usr/local/zabbix/bin/zabbix_sender'zabbix_conf='/usr/local/zabbix/conf/zabbix_agentd.conf'send_to_zabbix=1#getzookeeperserverstatusclassZooKeeperServer(object):def__init__(self,host='localhost',port='2181',timeout=1):self._address=(host,int(port))self._timeout=timeoutself._result={}def_create_socket(self):returnsocket.socket()def_send_cmd(self,cmd):"""Senda4letterwordcommandtotheserver"""s=self._create_socket()s.settimeout(self._timeout)s.connect(self._address)s.send(cmd)data=s.recv(2048)s.close()returndatadefget_stats(self):"""GetZooKeeperserverstatsasamap""""""zk_version3.4.6-1569965,builton02/20/09:09GMTzk_avg_latency0zk_max_latency94zk_min_latency0zk_packets_received1267904zk_packets_sent1317835zk_num_alive_connections12zk_outstanding_requests0zk_server_statefollowerzk_znode_count1684zk_watch_count2757zk_ephemerals_count899zk_approximate_data_size728074zk_open_file_descriptor_count41zk_max_file_descriptor_count4096"""data_mntr=self._send_cmd('mntr')data_ruok=self._send_cmd('ruok')ifdata_mntr:result_mntr=self._parse(data_mntr)ifdata_ruok:#{'zk_server_ruok':'imok'}result_ruok=self._parse_ruok(data_ruok)self._result=dict(result_mntr.items()+result_ruok.items())ifnotself._result.has_key('zk_followers')andnotself._result.has_key('zk_synced_followers')andnotself._result.has_key('zk_pending_syncs'):#####thetreemetricsonlyexposedonleaderrolezookeeperserver,wejustsetthefollowers'to0leader_only={'zk_followers':0,'zk_synced_followers':0,'zk_pending_syncs':0}self._result=dict(result_mntr.items()+result_ruok.items()+leader_only.items())returnself._resultdef_parse(self,data):""":paramdata:zk_outstanding_requests0zk_approximate_data_size653931:return:{'zk_outstanding_requests':'0','zk_approximate_data_size':'653931',}""""""Parsetheoutputfromthe'mntr'4letterwordcommand"""h=StringIO(data)result={}forlineinh.readlines():try:key,value=self._parse_line(line)result[key]=valueexceptValueError:pass#ignorebrokenlinesreturnresultdef_parse_ruok(self,data):""":paramdata:imok:return:{'zk_server_ruok':'imok'}""""""Parsetheoutputfromthe'ruok'4letterwordcommand"""h=StringIO(data)result={}ruok=h.readline()ifruok:result['zk_server_ruok']=ruokreturnresultdef_parse_line(self,line):#zk_watch_count1482try:#zk_max_file_descriptor_count65535key,value=map(str.strip,line.split('\t'))exceptValueError:raiseValueError('Foundinvalidline:%s'%line)ifnotkey:raiseValueError('Thekeyismandatoryandshouldnotbeempty')try:value=int(value)except(TypeError,ValueError):passreturnkey,valuedefget_pid(self):#ps-ef|grepjava|grepzookeeper|awk'{print$2}'pidarg='''ps-ef|grepjava|grepzookeeper|grep-vgrep|awk'{print$2}''''#31022pidout=subprocess.Popen(pidarg,shell=True,stdout=subprocess.PIPE)pid=pidout.stdout.readline().strip('\n')returnpiddefsend_to_zabbix(self,metric):#key=zookeeper.status[zk_max_file_descriptor_count]key="zookeeper.status["+metric+"]"ifsend_to_zabbix>0:#printkey+":"+str(self._result[metric])try:subprocess.call([zabbix_sender,"-c",zabbix_conf,"-k",key,"-o",str(self._result[metric])],stdout=FNULL,stderr=FNULL,shell=False)#print"sendzabbixsuccess"exceptOSError,detail:print"Somethingwentwrongwhileexectutingzabbix_sender:",detailelse:print"Simulation:thefollowingcommandwouldbeexecucted:\n",zabbix_sender,"-c",zabbix_conf,"-k",key,"-o",self._result[metric],"\n"defusage():"""Displayprogramusage"""print"\nUsage:",sys.argv[0],"alive|all"print"Modes:\n\talive:Returnpidofrunningzookeeper\n\tall:Sendzookeeperstatsaswell"sys.exit(1)accepted_modes=['alive','all']iflen(sys.argv)==2andsys.argv[1]inaccepted_modes:mode=sys.argv[1]else:usage()zk=ZooKeeperServer()#printzk.get_stats()pid=zk.get_pid()ifpid!=""andmode=='alive':zk.get_stats()#printzk._resultFNULL=open(os.devnull,'w')forkeyinzk._result:zk.send_to_zabbix(key)FNULL.close()printpid
下面为原代码的最后部分,同时贴出,对比下逻辑, 如果有我的方式有问题, 请留言指正, 新手感谢 .
ifpid!=""andmode=='all':zk.get_stats()#printzk._resultFNULL=open(os.devnull,'w')forkeyinzk._result:zk.send_to_zabbix(key)FNULL.close()printpidelifpid!=""andmode=="alive":printpidelse:print0
Zabbix_agentd获取
参考了上一种方式中的python脚本,经过修改, 所有数据都通过agentd的方式获取数据.
一下为修改后的python脚本,个人感觉shell实现很简单,但是作为一个python初学者,还是自己修改了下,功能实现了.
#!/usr/bin/python#monitorzookeeper#bymoimportsysimportsocketimportreimportsubprocessfromStringIOimportStringIOimportosclassZooKeeperServer(object):def__init__(self,host='localhost',port='2181',timeout=1):self._address=(host,int(port))self._timeout=timeoutself._result={}def_create_socket(self):returnsocket.socket()def_send_cmd(self,cmd):"""Senda4letterwordcommandtotheserver"""s=self._create_socket()s.settimeout(self._timeout)s.connect(self._address)s.send(cmd)data=s.recv(2048)s.close()returndatadefget_pid(self):#ps-ef|grepjava|grepzookeeper|awk'{print$2}'pidarg='''ps-ef|grepjava|grepzookeeper|grep-vgrep|awk'{print$2}''''#31022pidout=subprocess.Popen(pidarg,shell=True,stdout=subprocess.PIPE)pid=pidout.stdout.readline().strip('\n')returnpiddef_parse(self,data):""":paramdata:zk_outstanding_requests0zk_approximate_data_size653931:return:{'zk_outstanding_requests':'0','zk_approximate_data_size':'653931',}""""""Parsetheoutputfromthe'mntr'4letterwordcommand"""h=StringIO(data)result={}forlineinh.readlines():try:key,value=self._parse_line(line)result[key]=valueexceptValueError:pass#ignorebrokenlinesreturnresultdef_parse_line(self,line):#zk_watch_count1482try:#zk_max_file_descriptor_count65535key,value=map(str.strip,line.split('\t'))exceptValueError:raiseValueError('Foundinvalidline:%s'%line)ifnotkey:raiseValueError('Thekeyismandatoryandshouldnotbeempty')try:value=int(value)except(TypeError,ValueError):passreturnkey,valuedefget_stats(self):"""GetZooKeeperserverstatsasamap""""""zk_version3.4.6-1569965,builton02/20/09:09GMTzk_avg_latency0zk_max_latency94zk_min_latency0zk_packets_received1267904zk_packets_sent1317835zk_num_alive_connections12zk_outstanding_requests0zk_server_statefollowerzk_znode_count1684zk_watch_count2757zk_ephemerals_count899zk_approximate_data_size728074zk_open_file_descriptor_count41zk_max_file_descriptor_count4096"""data_mntr=self._send_cmd('mntr')result_mntr=self._parse(data_mntr)self._result=dict(result_mntr.items())returnself._resultzk=ZooKeeperServer()pid=zk.get_pid()accepted_modes=['zk_server_ruok']ifsys.argv[1]inaccepted_modes:cmd=sys.argv[1]data=zk._send_cmd(cmd)print(data)elifsys.argv[1]=='alive':print(pid)elifsys.argv[1]=='mntr':cmd=sys.argv[1]data=zk._send_cmd(cmd)print(data)else:zk.get_stats()key=sys.argv[1]print(zk._result[key])
模版
参考博文中的模版
<?xmlversion="1.0"encoding="UTF-8"?><zabbix_export><version>3.0</version><date>-12-11T08:02:58Z</date><groups><group><name>Zabbixservers</name></group></groups><templates><template><template>Zookeeper</template><name>Zookeeper</name><description/><groups><group><name>Zabbixservers</name></group></groups><applications><application><name>ZooKeeperStatus</name></application></applications><items><item><name>zookeeperpid</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[alive]</key><delay>10</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperapproximatedatasize</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_approximate_data_size]</key><delay>0</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperaveragelatency</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_avg_latency]</key><delay>0</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperephemeralscount</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_ephemerals_count]</key><delay>0</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperleader'sfollowers</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_followers]</key><delay>0</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeepermaxfiledescriptorcount</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_max_file_descriptor_count]</key><delay>10</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeepermaxlatency</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_max_latency]</key><delay>10</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperminlatency</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_min_latency]</key><delay>10</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperaliveconnections</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_num_alive_connections]</key><delay>0</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperopenedfiledescriptorcount</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_open_file_descriptor_count]</key><delay>10</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperoutstandingrequests</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_outstanding_requests]</key><delay>10</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperpackagesreceived</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_packets_received]</key><delay>10</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description>收包数量</description><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperpackagessent</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_packets_sent]</key><delay>10</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description>发包数据量</description><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperleader'spendingsyncs</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_pending_syncs]</key><delay>10</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperresponsechecking</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_server_ruok]</key><delay>10</delay><history>90</history><trends>0</trends><status>0</status><value_type>1</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperstaterole</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_server_state]</key><delay>10</delay><history>90</history><trends>0</trends><status>0</status><value_type>1</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperleader'ssyncedfollowers</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_synced_followers]</key><delay>10</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperversion</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_version]</key><delay>10</delay><history>90</history><trends>0</trends><status>0</status><value_type>1</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperwatchescount</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_watch_count]</key><delay>10</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item><item><name>zookeeperznodescount</name><type>2</type><snmp_community/><multiplier>0</multiplier><snmp_oid/><key>zookeeper.status[zk_znode_count]</key><delay>10</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts/><units/><delta>0</delta><snmpv3_contextname/><snmpv3_securityname/><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authprotocol>0</snmpv3_authprotocol><snmpv3_authpassphrase/><snmpv3_privprotocol>0</snmpv3_privprotocol><snmpv3_privpassphrase/><formula>1</formula><delay_flex/><params/><ipmi_sensor/><data_type>0</data_type><authtype>0</authtype><username/><password/><publickey/><privatekey/><port/><description/><inventory_link>0</inventory_link><applications><application><name>ZooKeeperStatus</name></application></applications><valuemap/><logtimefmt/></item></items><discovery_rules/><macros/><templates/><screens/></template></templates><triggers><trigger><expression>{Zookeeper:zookeeper.status[zk_outstanding_requests].last()}>10</expression><name>bigoutstandingrequestsnumber</name><url/><status>0</status><priority>0</priority><description/><type>0</type><dependencies/></trigger><trigger><expression>{Zookeeper:zookeeper.status[zk_pending_syncs].last()}>10</expression><name>bigpendingsyncs</name><url/><status>0</status><priority>0</priority><description/><type>0</type><dependencies/></trigger><trigger><expression>{Zookeeper:zookeeper.status[zk_avg_latency].last()}>10</expression><name>largeaveragelatency</name><url/><status>0</status><priority>0</priority><description/><type>0</type><dependencies/></trigger><trigger><expression>{Zookeeper:zookeeper.status[zk_open_file_descriptor_count].last()}>{Zookeeper:zookeeper.status[zk_max_file_descriptor_count].last()}*0.85</expression><name>largefiledescriptorused</name><url/><status>0</status><priority>0</priority><description/><type>0</type><dependencies/></trigger><trigger><expression>{Zookeeper:zookeeper.status[zk_server_ruok].str(imok)}<>1</expression><name>zookeeperisabnormal</name><url/><status>0</status><priority>4</priority><description/><type>0</type><dependencies/></trigger><trigger><expression>{Zookeeper:zookeeper.status[alive].last()}=0</expression><name>zookeeperisnotrunning</name><url/><status>0</status><priority>4</priority><description/><type>0</type><dependencies/></trigger><trigger><expression>{Zookeeper:zookeeper.status[zk_server_state].abschange()}>0</expression><name>zookeeperstaterolehasbeenchanged</name><url/><status>0</status><priority>1</priority><description/><type>0</type><dependencies/></trigger></triggers><graphs><graph><name>ZooKeeperAliveConnections</name><width>900</width><height>200</height><yaxismin>0.0000</yaxismin><yaxismax>100.0000</yaxismax><show_work_period>1</show_work_period><show_triggers>1</show_triggers><type>0</type><show_legend>1</show_legend><show_3d>0</show_3d><percent_left>0.0000</percent_left><percent_right>0.0000</percent_right><ymin_type_1>0</ymin_type_1><ymax_type_1>0</ymax_type_1><ymin_item_1>0</ymin_item_1><ymax_item_1>0</ymax_item_1><graph_items><graph_item><sortorder>0</sortorder><drawtype>0</drawtype><color>1A7C11</color><yaxisside>0</yaxisside><calc_fnc>2</calc_fnc><type>0</type><item><host>Zookeeper</host><key>zookeeper.status[zk_num_alive_connections]</key></item></graph_item></graph_items></graph><graph><name>ZooKeeperLatency</name><width>900</width><height>200</height><yaxismin>0.0000</yaxismin><yaxismax>100.0000</yaxismax><show_work_period>1</show_work_period><show_triggers>1</show_triggers><type>0</type><show_legend>1</show_legend><show_3d>0</show_3d><percent_left>0.0000</percent_left><percent_right>0.0000</percent_right><ymin_type_1>0</ymin_type_1><ymax_type_1>0</ymax_type_1><ymin_item_1>0</ymin_item_1><ymax_item_1>0</ymax_item_1><graph_items><graph_item><sortorder>0</sortorder><drawtype>0</drawtype><color>1A7C11</color><yaxisside>0</yaxisside><calc_fnc>2</calc_fnc><type>0</type><item><host>Zookeeper</host><key>zookeeper.status[zk_avg_latency]</key></item></graph_item></graph_items></graph></graphs></zabbix_export>
Zabbix_agentd配置
UserParameter=zookeeper.status[*],/usr/bin/python/usr/local/zabbix/scripts/zookeeper_monitor.py$1
###
注意:给脚本执行权限