- A+
1. 概述
本篇文章是zabbix发现的最后一篇,回顾一下前面几篇文章
- 《zabbix发现介绍》整个功能的介绍
- 《zabbix发现配置》server通过配置好的规则,自动添加host、group、template
- 《zabbix Active agent自动注册》与discovery相反,功能基本相同,active联系server,server自动添加host、group、template
以上目的都是发现host、添加host,本文的low-level discovery更底层点,用于发现item、trigger、graph等等。我们最常用如:filesystem(如/、/home、/proc、C:、D:等),network(eth0,eth1等)
2. Discovery之文件系统
众多服务器,难免系统以及分区会有所不同。一般存在linux和windows两种系统,linux下分区有/、/data、/proc等等,windows有C:D:E:等,A服务器有/data分区,B服务器可能有/site分区。他有什么分区,我便监控什么分区,这就是low-level discovery的功能。
2.1 创建模板
创建模板A_Template_For_Discovery,.....过程省略....
2.2 配置discovery规则
configuration>>templates>>找到模板“A_Template_For_Discovery”>>Discovery(0)>>Create discovery rule
属性说明:
Keep lost resources period(in days):数据保留天数,默认30天
Fileter:Macro为{#FSNAME},key “vfs.fs.discovery”返回json数据列表,里面内容为{#FSNAME}作为key,/、/data、C:等等作为value。regext可以使用表达式,例如"^/data|/C:",如果想通过{#FSTYPE}来过滤,那么Macro写{#FSTYPE},regexp写^(ext2|ext3|swap)$,或者引入zabbix中定义好的的正则表达式,@表达式名称。关于《zabbix正则表达式》请继续关注ttlsa。
2.3 创建Item prototypes
其实就是一个创建一个item,configuration>>templates>>找到模板“A_Template_For_Discovery”>>Discovery(1)>>find file system>>Item prototypes (0)>>create Item prototypes
2.4 创建Trigger
当剩余量小于20%触发warnning
configuration>>templates>>找到模板“A_Template_For_Discovery”>>Discovery(1)>>find file system>>Trigger prototypes (0)>>Create trigger prototypes
与普通的trigger区别在{#FSNAME}
2.4 创建graph
绘制简单图表
configuration>>templates>>找到模板“A_Template_For_Discovery”>>Discovery(1)>>find file system>>Graph prototypes (0)>>Create Graph prototypes
3. 自定义LLD规则
系统已经内建了文件系统的{#FSNAME},网络的{#IFNAME},因为业务的特殊性,我们如何定义我们自己需要的名称呢?
- 编写脚本,脚本输出json数据,包含key和value
- 脚本加入zabbix_agentd.conf UserParameter
- 重启zabbix_agentd
- 使用定义好的名称配置low-level discovery
3.1 脚本范例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#!/usr/bin/perl $first = 1; print "{\n"; print "\t\"data\":[\n\n"; for (`cat /proc/mounts`) { ($fsname, $fstype) = m/\S+ (\S+) (\S+)/; $fsname =~ s!/!\\/!g; print "\t,\n" if not $first; $first = 0; print "\t{\n"; print "\t\t\"{#FSNAME}\":\"$fsname\",\n"; print "\t\t\"{#FSTYPE}\":\"$fstype\"\n"; print "\t}\n"; } print "\n\t]\n"; print "}\n"; |
3.2 结果范例
执行后得到如下数据,是json格式
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
{ "data":[ { "{#FSNAME}":"\/", "{#FSTYPE}":"rootfs" } , { "{#FSNAME}":"\/proc", "{#FSTYPE}":"proc" } , { "{#FSNAME}":"\/sys", "{#FSTYPE}":"sysfs" } , { "{#FSNAME}":"\/dev", "{#FSTYPE}":"devtmpfs" } , { "{#FSNAME}":"\/dev\/pts", "{#FSTYPE}":"devpts" } , { "{#FSNAME}":"\/dev\/shm", "{#FSTYPE}":"tmpfs" } , { "{#FSNAME}":"\/", "{#FSTYPE}":"ext4" } , { "{#FSNAME}":"\/proc\/bus\/usb", "{#FSTYPE}":"usbfs" } , { "{#FSNAME}":"\/proc\/xen", "{#FSTYPE}":"xenfs" } , { "{#FSNAME}":"\/proc\/sys\/fs\/binfmt_misc", "{#FSTYPE}":"binfmt_misc" } ] } |
zabbix discovery到此结束,想获取更多zabbix技能,请继续关注ttlsa.com

13/01/2016 下午 3:10 沙发
弱弱的问下:Item prototypes 这个类型可以是计算的么?
09/06/2015 下午 4:23 板凳
博主你好,我想问一下low level discover在使用的时候只能使用脚本方式吗?我想通过model方式将我的数据进行封装,但是不知道如何实现key和value对,请问你在这上面有好的经验吗?
09/06/2015 下午 4:59 1层
@游客15 已搞定。。。