Zabbix发现、自动注册和web监控

  1. 云栖社区>
  2. 博客>
  3. 正文

Zabbix发现、自动注册和web监控

技术小胖子 2017-11-08 07:36:00 浏览971
展开阅读全文

一、网络发现

网络发现是zabbix最具特色的功能之一,它能能够根据用户事先定义的规则自动添加监控主机或服务等,Zabbix的网络发现功能可以基于:IP ranges、Availability of external services(FTP、SSH、WEB、POP3、IMAP、TCP、etc)、Information recevived from zabbix agent、Information recevived from SNMP agent.

网络发现通常包含两个阶段:discovery和actions

Discovery中的事件:

Service Up

Service Down

Host Up

Host Down

Service Discovered

Service Lost

Host Discovered

Host Lost


Action,网络发现中的事件可以触发action,从而自动执行指定的操作,如:

Sending notifications

Adding/removing hosts

Enabling/disabling hosts

Adding hosts to group

Removing hosts from a group

Linking hosts to/unlinking from a template

Executing remote scripts




二、自动注册

Zabbix支持active agent的自动注册(auto-resisitration)功能,通常用于此前故障的agent重新上线的场景,也可基于active agent的自动注册机制添加被动检测,这会通过active agent注册时提供的"ListenIP"和"ListenPort"进行,Server端在收到自动注册请求后以接收到的IP和Port为接口属性。



实验环境

192.168.30.116   OS:CentOS 6.4 x86_64   zabbix_server.luojianlong.com

192.168.30.117   OS:CentOS 6.4 x86_64   node1.luojianlong.com

192.168.30.119   OS:CentOS 6.4 x86_64   node2.luojianlong.com

192.168.30.115   OS:CentOS 6.4 x86_64   node3.luojianlong.com


zabbix_server,zabbix_agent已经安装完成,并且启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@zabbix_server ~]# netstat -anptl | grep zabbix
tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      19539/zabbix_server
tcp        0      0 192.168.30.116:36692        192.168.30.116:3306         ESTABLISHED 19567/zabbix_server
tcp        0      0 192.168.30.116:36681        192.168.30.116:3306         ESTABLISHED 19569/zabbix_server
tcp        0      0 192.168.30.116:36684        192.168.30.116:3306         ESTABLISHED 19576/zabbix_server
tcp        0      0 192.168.30.116:36677        192.168.30.116:3306         ESTABLISHED 19559/zabbix_server
tcp        0      0 192.168.30.116:36680        192.168.30.116:3306         ESTABLISHED 19566/zabbix_server
tcp        0      0 192.168.30.116:36682        192.168.30.116:3306         ESTABLISHED 19570/zabbix_server
tcp        0      0 192.168.30.116:54102        192.168.30.116:3306         ESTABLISHED 19547/zabbix_server
tcp        0      0 192.168.30.116:36685        192.168.30.116:3306         ESTABLISHED 19572/zabbix_server
tcp        0      0 192.168.30.116:58705        192.168.30.116:3306         ESTABLISHED 19546/zabbix_server
tcp        0      0 192.168.30.116:58706        192.168.30.116:3306         ESTABLISHED 19544/zabbix_server
tcp        0      0 192.168.30.116:36679        192.168.30.116:3306         ESTABLISHED 19563/zabbix_server
tcp        0      0 192.168.30.116:53068        192.168.30.116:3306         ESTABLISHED 19543/zabbix_server
tcp        0      0 192.168.30.116:36694        192.168.30.116:3306         ESTABLISHED 19541/zabbix_server
tcp        0      0 192.168.30.116:36683        192.168.30.116:3306         ESTABLISHED 19574/zabbix_server
tcp        0      0 192.168.30.116:54112        192.168.30.116:3306         ESTABLISHED 19548/zabbix_server
tcp        0      0 :::10051                    :::*                        LISTEN      19539/zabbix_server
[root@node1 ~]# netstat -anplt | grep zabbix
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      26800/zabbix_agentd
tcp        0      0 :::10050                    :::*                        LISTEN      26800/zabbix_agentd


下面开始创建模板

wKioL1NN_a-z5n4jAAIRoHy6pgs924.jpg


为模板添加items

wKiom1NN_r7wxAqlAAK06k1CaAo136.jpg



wKiom1NN_zGi8RrUAAKRL7HEoxQ150.jpg


wKioL1NN_xCADBPVAANl9UUNzck967.jpg


创建graph

wKioL1NOADXxnUPeAAKndvHgCQA230.jpgwKiom1NOAJvgLH2hAALuAP9x6rc642.jpg

wKioL1NOAJSx8AXWAAOfAGQZSEk443.jpg


下面定义discovery rules,发现地址范围为:192.168.30.110-120

超时时间为:120s

检测的key为:刚才在item中定义的net.if.in[eth0]

检测标准为: IP address


wKioL1NOAY3RYcuUAAMRxeOYhRk279.jpg



wKioL1NOAjaRHq8WAAOrQHfki58102.jpg



定义actions,Event source选择Discovery

wKiom1NOAsOxL3gNAAOqW-_nlFQ633.jpg


定义发现action名称,发送消息,主题

wKioL1NOA46gpAm2AAMu3uV0vEs892.jpg


定义Operations,添加类型为host,link到之前创建的模板


wKiom1NOBAjBsX07AALhAM0w_lQ269.jpg


定义Conditions,Discovery rule必须为Linux in localnet,Discovery status为:Discovered

主机IP在:192.168.30.110-120内

wKioL1NOBBzCfr2zAANFOJAu_uw739.jpg



wKiom1NOBJfyB42pAARW2E4c2g0273.jpg


定义移除action,只要探测失败,就移除主机

wKioL1NOB-iSkwXJAAMkjq4ctz8436.jpg

wKiom1NOCH2yicPZAAK7dQ3U_y0421.jpg



wKiom1NOCQOAF4b8AAMNhiw9LBI546.jpg


wKioL1NOCPeieuZbAAS-54AC3ME034.jpg


观察是发现3台主机

wKioL1NOCXnz77WJAAI9F4OkLDY362.jpg


发现主机已经被自动添加监控,并链接至模板

wKiom1NOCgTzuVmZAASe7MDILhc391.jpg


测试,主机下线,看是否会被移除

1
2
3
4
5
6
[root@node1 ~]# service zabbix-agent stop
Shutting down Zabbix agent:                                [  OK  ]
[root@node2 ~]# service zabbix-agent stop
Shutting down Zabbix agent:                                [  OK  ]
[root@node3 ~]# service zabbix-agent stop
Shutting down Zabbix agent:                                [  OK  ]



wKioL1NOCpKiDiFFAAIourVbBTM059.jpg

发现主机被自动移除

wKiom1NOCzqgfIB6AANmLhqxq9I058.jpg


测试,恢复上线

1
2
3
4
5
6
[root@node1 ~]# service zabbix-agent start
Starting Zabbix agent:                                     [  OK  ]
[root@node2 ~]# service zabbix-agent start
Starting Zabbix agent:                                     [  OK  ]
[root@node3 ~]# service zabbix-agent start
Starting Zabbix agent:                                     [  OK  ]



wKiom1NOC5yQNKX9AAHdJWOIaKs065.jpg


wKiom1NOC8OQZU4tAASeUOB2QCc371.jpg


发现3个主机已经恢复监控



下面创建web监控

首先,在192.168.30.115主机中定义application

wKiom1NOFD_Ah1Z4AAK0_q_zcRw710.jpg

wKioL1NOFEjwsE9fAAQhyreK77I015.jpg


然后创建 web senario

wKioL1NOFPvRcFc5AALk4OUE4QM694.jpg


定义steps

wKioL1NOFVDwt04iAALkyXGS734472.jpg

wKioL1NOFZPxOCMnAAMGMyr2hMA265.jpg


wKioL1NOFbCAP9PsAAOxZPXiB1c985.jpg


下面查看图像

wKiom1NOFlPCiX7zAAVr2J3wqKo338.jpg


wKiom1NOFmnS2YBaAATmI_qNdgM233.jpg


可以看到页面的响应速度和下载速度


创建web监控的trigger,表达式为主页最后一次的响应码不等于200就触发事件


wKiom1NOGy3CwbkmAANTzYdCeM4632.jpg


wKiom1NOGuOCsteIAAJuocAxYoU937.jpg






模拟故障

1
[root@node1 ~]# killall -9 nginx


wKioL1NOGy_ARsTaAANTo2qOaIY080.jpg


发现触发器生效







     本文转自ljl_19880709 51CTO博客,原文链接:http://blog.51cto.com/luojianlong/1396320,如需转载请自行联系原作者




网友评论

登录后评论
0/500
评论
技术小胖子
+ 关注