发布于 2014-11-28 00:24:22 | 2567 次阅读 | 评论: 0 | 来源: 网友投递
Zabbix 分布式系统监视系统
zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
本文主要为大家讲解了 zabbix 自定义LLD的实现方法步骤,感兴趣的同学参考下。
新版本的zabbix支持custom LLD,实现步骤如下:
1.在模板中设置一个discovery rule ( UserParameter Key),调用脚本,返回zabbix规定的json数据(返回自定义的宏变量),并正确设置的discovery(比如filter等)
这里通过官方文档并结合线上的agent日志,可以看到zabbix规定的数据格式
143085:20141127:000548.967 Requested [vfs.fs.discovery]143085:20141127:000548.967 Sending back [{"data":[{"{#FSNAME}":"\/","{#FSTYPE}":"rootfs"},{"{#FSNAME}":"\/proc\/sys\/fs\/binfmt_misc","{#FSTYPE}":"binfmt_misc"},{"{#FSNAME}":"\/data","{#FSTYPE}":"ext4"}]}]
比如线上返回json数据的key:
UserParameter=storm.delay.discovery,python2.6/apps/sh/zabbix_scripts/storm/storm_delay_discovery.py
并通过
zabbix_get -s 127.0.0.1 -k storm.delay.discovery
验证返回数据的准确性
storm_delay_discovery.py内容如下:
#!/usr/bin/pythonimportsysimportredisimportexceptionsimporttraceback_hashtables=[]_continue=True_alldict={}_alllist=[]classRedisException(Exception):def__init__(self, errorlog):self.errorlog=errorlogdef__str__(self):return"error log is %s"%(self.errorlog)defscan_one(cursor,conn):try:cursor_v=conn.scan(cursor)cursor_next=cursor_v[0]cursor_value=cursor_v[1]forlineincursor_value:if(line.startswith("com-vip-storm")orline.startswith("stormdelay_"))andstr(line) !="stormdelay_riskcontroll":_hashtables.append(line)else:passreturncursor_nextexceptException,e:raiseRedisException(str(e))defscan_all(conn):try:cursor1=scan_one('0',conn)global_continuewhile_continue:cursor2=scan_one(cursor1,conn)ifint(cursor2)==0:_continue=Falseelse:cursor1=cursor2_continue=TrueexceptException,e:raiseRedisException(str(e))defhget_fields(conn,hashname):onedict={}fields=conn.hkeys(hashname)forfieldinfields:onedict["{#STORMHASHNAME}"]=hashnameonedict["{#STORMHASHFIELD}"]=field_alllist.append(onedict)if__name__=='__main__':try:r=redis.StrictRedis(host='xxxx', port=xxx, db=0)scan_all(r)forhashtablein_hashtables:hget_fields(r,hashtable)_alldict["data"]=_allliststr(_alldict).replace("'",'"')exceptException,e:-1
2.设置item/graph/trigger prototypes:
这里以item为例,定义item prototypes (同样需要定义key),key的参数为宏变量
比如Free inodes on {#FSNAME} (percentage)--->vfs.fs.inode[{#FSNAME},pfree]
本例中,在item中使用上面返回的宏变量即可,
storm_delay[hget,{#STORMHASHNAME},{#STORMHASHFIELD}]
最后,把包含LLD的template链接到host上即可。
最后再配合screen.create/screenitem.update api就可以实现监控添加/screen添加,更新的自动化了。