感觉这个主题是和一个主题是一个系列,而且更基础。

准备深入研究一下。。。

相关文档准备:

https://www.zabbix.com/documentation/2.0/manual/discovery/low_level_discovery

http://itnihao.blog.51cto.com/1741976/1129725

Low-level discovery provides a way to automatically create items, triggers, and graphs for different entities on a computer. For instance, Zabbix can automatically start monitoring file systems or network interfaces on your machine, without the need to create items for each file system or network interface manually. Additionally it is possible to configure Zabbix to remove unneeded entities automatically based on actual results of periodically performed discovery.

In Zabbix 2.0, three types of item discovery are supported out of the box:

  • discovery of file systems;
  • discovery of network interfaces;
  • discovery of SNMP OIDs.

A user can define their own types of discovery, provided they follow a particular JSON protocol.

The general architecture of the discovery process is as follows.

First, a user creates a discovery rule in “Configuration” → “Templates” → “Discovery” column. A discovery rule consists of (1) an item that discovers the necessary entities (for instance, file systems or network interfaces) and (2) prototypes of items, triggers, and graphs that should be created based on the value of that item.

An item that discovers the necessary entities is like a regular item seen elsewhere: the server asks a Zabbix agent (or whatever the type of the item is set to) for a value of that item, the agent responds with a textual value. The difference is that the value the agent responds with should contain a list of discovered entities in a specific JSON format. While the details of this format are only important for implementers of custom discovery checks, it is necessary to know that the returned value contains a list of macro → value pairs. For instance, item “net.if.discovery” might return two pairs: “{#IFNAME}” → “lo” and “{#IFNAME}” → “eth0”.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

需求:

现在有大量url需要监控,形式如http://itnihao.blog.51cto.com ,要求url状态不为200即报警。

需求详细分析:

大量的url,且url经常变化,现在监控用的是zabbix,如果手动添加模板,会造成大量重复工作,造成人力财力的浪费,造成休息时间的浪费,得不尝失,如果利用脚本+mail,无法图形呈现

解决方案:

zabbix有discovery功能,利用此功能,即可轻松解决此问题

zabbix客户端配置

  1. #########cat /etc/zabbix/zabbix_agentd.conf|grep -v "^#"|grep -v "^$"##########

  2. ##此处省略N多信息,

  3. Include=/etc/zabbix/zabbix_agentd.conf.d/   #配置文件路径

  4. UnsafeUserParameters=1                      #自定义key

  1. ###########自动发现脚本编写

  2. ########################cat /etc/zabbix/scripts/web_site_code_status##############

  3. #!/bin/bash

  4. # function:monitor tcp connect status from zabbix

  5. # License: GPL

  6. # mail:itnihao@qq.com

  7. # version:1.0 date:2012-12-09

  8. source /etc/bashrc >/dev/null 2>&1

  9. source /etc/profile  >/dev/null 2>&1

  10. #/usr/bin/curl -o /dev/null -s -w %{http_code} http://$1/

  11. WEB_SITE_discovery () {

  12. WEB_SITE=($(cat  WEB1.txt|grep -v "^#"))

  13. printf '{\n'

  14. printf '\t"data":[\n'

  15. for((i=0;i<${#WEB_SITE[@]};++i))

  16. {

  17. num=$(echo $((${#WEB_SITE[@]}-1)))

  18. if [ "$i" != ${num} ];

  19. then

  20. printf "\t\t{ \n"

  21. printf "\t\t\t\"{#SITENAME}\":\"${WEB_SITE[$i]}\"},\n"

  22. else

  23. printf  "\t\t{ \n"

  24. printf  "\t\t\t\"{#SITENAME}\":\"${WEB_SITE[$num]}\"}]}\n"

  25. fi

  26. }

  27. }

  28. web_site_code () {

  29. /usr/bin/curl -o /dev/null -s -w %{http_code} http://$1

  30. }

  31. case "$1" in

  32. web_site_discovery)

  33. WEB_SITE_discovery

  34. ;;

  35. web_site_code)

  36. web_site_code $2

  37. ;;

  38. *)

  39. echo "Usage:$0 {web_site_discovery|web_site_code [URL]}"

  40. ;;

  41. esac

客户端配置文件

  1. #########cat /etc/zabbix/zabbix_agentd.conf.d/web_site_discovery.conf  ###########

  2. UserParameter=web.site.discovery,/etc/zabbix/scripts/web_site_code_status web_site_discovery

  3. UserParameter=web.site.code[*],/etc/zabbix/scripts/web_site_code_status web_site_code $1

域名如下

  1. ######### cat /etc/zabbix/scripts/WEB.txt###########

  2. www.qq.com

  3. www.baidu.com

  4. www.sina.com.cn

测试:

  1. zabbix_get -s 127.0.0.1 -k web.site.discovery

  1. zabbix_get -s 127.0.0.1 -k web.site.code[www.qq.com]

此时返回状态为200

至此,脚本,客户端配置文件OK

接下来是web的添加

报警级别的设置:3个报警级别

利用以上方法,哪怕是1000个url监控,也是分分钟的事情

总结:工欲善其事,必先利其器

参考文档:https://www.zabbix.com/documentation/2.0/manual/discovery/low_level_discovery

此外,还可以参考我写的文档:http://code.google.com/p/auto-task-pe/downloads/list  zabbix自动发现监控http端口.pdf   如遇到问题,请先仔细阅读这2个文档,另外附模板文件。

欢迎交流。

http://my.itwnik.com/2013/03/zabbix-low-level-discovery-rule-script-for-md-devices/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

应用一则:

zabbix实现对web的监控有两种方式实现,一种是自带的web scenarios,基本能够实现大部分web监控的需求,但是方便简易性差很多;另一种是利用脚本+lld,可以实现任一机

器上的所有url监控,我们只需手动添加要监控的url,再加上zabbix模版的功能,就能够轻而易举的应用到所需要的监控的服务器上。

首先要感线itnihao童鞋提供的这种方式,博客地址为http://itnihao.blog.51cto.com/1741976/1129725

1.zabbix客户端配置

vim /etc/zabbix/zabbix_agent.conf

Include=/etc/zabbix/zabbix_agentd.conf

UnsafeUserParameters=1

允许用户使用自定义的参数进行传递

2.脚本及参数

[root@localhost zabbix]# tree
.
├── monitor_scripts
│   ├── discovertcpport.sh
│   ├── web_site_code_status.sh
│   └── WEB.txt
├── zabbix_agentd.conf
└── zabbix_agentd.d
    ├── userparameter_mysql.conf
    └── web_site_discovery.conf

(1)zabbix传递参数及配置文件

[root@localhost zabbix]# cat zabbix_agentd.d/web_site_discovery.conf 
UserParameter=web.site.discovery,/etc/zabbix/monitor_scripts/web_site_code_status.sh web_site_discovery  
UserParameter=web.site.code[*],/etc/zabbix/monitor_scripts/web_site_code_status.sh web_site_code $1

(2)zabbix自动监控脚本

[root@localhost zabbix]# cat monitor_scripts/web_site_code_status.sh 
#!/bin/bash
#function:monitor web site code status from zabbix 
WEB_SITE_discovery(){
WEB_SITE=($(cat /etc/zabbix/monitor_scripts/WEB.txt |grep -v "^#"))
printf '{\n'
printf '\t"data":[\n'
for((i=0;i<${#WEB_SITE[@]};i++))
{
num=$(echo $((${#WEB_SITE[@]}-1)))
if [ "$i" != ${num} ];then
printf "\t\t{ \n"
printf "\t\t\t\"{#SITENAME}\":\"${WEB_SITE[$i]}\"},\n"
else
printf "\t\t{ \n"
printf "\t\t\t\"{#SITENAME}\":\"${WEB_SITE[$num]}\"}]}\n"
fi
}
}
web_site_code(){
/usr/bin/curl -o /dev/null -s -w %{http_code} http://$1
}
case "$1" in
web_site_discovery)
WEB_SITE_discovery
;;
web_site_code)
web_site_code $2
;;
*)
echo "Usage:$0 {web_site_discovery|web_site_code[URL]}"
;;
esac

(3)需要监控的url在WEB.TXT中

[root@localhost zabbix]# cat monitor_scripts/WEB.txt 
s1.xd.com/Default.aspx
s2.xd.com/Default.aspx

3.在zabbix服务端进行监控测试

[root@83 yum.repos.d]# /usr/bin/zabbix_get  -s 192.168.1.211 -p 10050 -k web.site.code[s1.xd.com/Default.aspx]
200

[root@83 yum.repos.d]# /usr/bin/zabbix_get  -s 192.168.1.211 -p 10050 -k web.site.discovery
{
"data":[

"{#SITENAME}":"s1.xd.com/Default.aspx"},

"{#SITENAME}":"s2.xd.com/Default.aspx"}]}

测试成功

4.下面我们来配置下discovery模版,配好后直接应用到服务器即可。

(1)创建模版,并应用到需要监控的服务器上

(2)在新建的Template Web Monitor模版的Application中创建新应用

(3)在在新建的Template Web Monitor模版的Discovery rules中创建新rule

(4)在新建的web.site.discovery中创建Item porototyoed

(5)在新建的web.site.discovery中创建Trigger porotypes,此处设置为状态码大于399就报警。

ok,配置完后我们的web url监控就完成了

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Zabbix的LLD功能--Low-level discovery的更多相关文章

  1. Zabbix监控Low level discovery实时监控网站URL状态

    今天我们来聊一聊Low level discovery这个功能,我们为什么要用到loe level discovery这个功能呢? 很多时候,在使用zabbix监控一些东西,需要对类似于Itens进行 ...

  2. zabbix监控redis多实例(low level discovery)

    对于多实例部署的tomcat.redis等应用,可以利用zabbix的low level discovery功能来实现监控,减少重复操作.  注:Zabbix版本: Zabbix 3.0.2 一.服务 ...

  3. zabbix(10)自动发现规则(low level discovery)

    1.概念 在配置Iterms的过程中,有时候需要对类似的Iterms进行添加,这些Iterms具有共同的特征,表现为某些特定的参数是变量,而其他设置都是一样的,例如:一个程序有多个端口,而需要对端口配 ...

  4. zabbix 用 LLD 完全自动化监控 Oracle

    文章转载自:http://mp.weixin.qq.com/s?__biz=MzA3MzYwNjQ3NA==&mid=2651296856&idx=1&sn=2bdf78071 ...

  5. Solr实现Low Level查询解析(QParser)

    Solr实现Low Level查询解析(QParser) Solr基于Lucene提供了方便的查询解析和搜索服务器的功能,可以以插件的方式集成,非常容易的扩展我们自己需要的查询解析方式.其中,Solr ...

  6. zabbix自动发现功能实现批量web url监控

    需求: 现在有大量url需要监控,形式如http://www.baidu.com ,要求url状态不为200即报警. 需求详细分析: 大量的url,且url经常变化,现在监控用的是zabbix,如果手 ...

  7. 使用Java Low Level REST Client操作elasticsearch

    Java REST客户端有两种风格: Java低级别REST客户端(Java Low Level REST Client,以后都简称低级客户端算了,难得码字):Elasticsearch的官方low- ...

  8. C++ Low level performance optimize 2

    C++ Low level performance optimize 2 上一篇 文章讨论了一些底层代码的优化技巧,本文继续讨论一些相关的内容. 首先,上一篇文章讨论cache missing的重要性 ...

  9. C++ Low level performance optimize

    C++ Low level performance optimize 1.  May I have 1 bit ? 下面两段代码,哪一个占用空间更少,那个速度更快?思考10秒再继续往下看:) //v1 ...

随机推荐

  1. libcurl使用演示样例

    简要说明:C++使用libcurl訪问"www.baidu.com".获取返回码和打印出http文件 /* * @ libcurl使用演示样例 * @ 2014.04.29 * @ ...

  2. linux下ntfs硬盘的加载

    问题:       # mount –t ntfs /dev/sdb1 /mnt/       mount: unknown filesystem type ‘ntfs’       这是由于Cent ...

  3. MapReduce分析明星微博数据

    互联网时代的到来,使得名人的形象变得更加鲜活,也拉近了明星和粉丝之间的距离.歌星.影星.体育明星.作家等名人通过互联网能够轻易实现和粉丝的互动,赚钱也变得前所未有的简单.同时,互联网的飞速发展本身也造 ...

  4. Cocos2d-x游戏开发中的消息机制:CCNotificationCenter的使用

    在HTML5游戏开发中,js可以使用Event对象的addEventListener(添加事件监听).dispatchEvent(触发事件)实现监听机制,如果在coocos2d-x中,去实现这种机制该 ...

  5. windows 下解决 Time_Wait 和 CLOSE_WAIT 方法

    修改Time_Wait参数的方法 (在服务端修改)Windows下在HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Paramet ...

  6. Android(java)学习笔记203:网页源码查看器(Handler消息机制)

    1.项目框架图: 2.首先是布局文件activity_main.xml: <LinearLayout xmlns:android="http://schemas.android.com ...

  7. PL/SQL Select into 异常处理

    在使用select into 为变量赋值时,如果变量是集合类型,不会产生异常,而如果是基本类型或记录类型,则会报异常. 异常产生了怎么办?当然是捕获并处理啦. 对于普通的代码块来说,在代码块的结尾处理 ...

  8. Android清单文件AndroidMenifest.xml

    1.AndroidMenifes.xml清单文主要结构件结构 所谓主要结构就是每一个清单文件中都必不可少的结构主要是下面三层 第一层.menifest 第二层.application,use-sdk ...

  9. js中浮点型运算 注意点

    先看张图: 这是一个JS浮点数运算Bug,导致我树状图,数据合计不正确,,,,,,两个小数相加,出来那么多位小数 (这是修该之后的) 网上找到以下解决方式: 方法一:有js自定义函数   <sc ...

  10. 微信小程序开发之入门篇(熟悉开发工具)

    个人的每一篇博文都谈不上有什么技术含量,只是为了帮助不熟悉微信小程序开发的自己及他人提供一下思路.谢谢,下面开始! PS: 因为本人没有小程序的内测资格,所以所有的开发及Demo都是无AppId的,如 ...