Zabbix LLD combined with Pycurl batch monitoring website service quality
Source: Internet
Author: User
<span id="Label3"></p><p><p>The first two days to see the blog has a monitoring of the web, before also written pycurl monitoring state; think of the web monitoring in the Back. why don't we just monitor it by zabbix? Zabbix is really a kaleidoscope, and this is one of the reasons I like Zabbix. Pycurl can refer to what I have written before: http://xiaoluoge.blog.51cto.com/9141967/1616922.</p></p><p><p><br></p></p><p><p><br></p></p><p><p>1. Monitoring Script:</p></p><pre class="brush:python;toolbar:false">[[email protected] scripts]# cat web_monitor.py #!/usr/bin/env python# -*- coding: utf-8 -*- import os,sys import time import sys import pycurl import jsonurllist=[' www.baidu.com ', ' www.hao123.com '] class test: def __init__ (self): self.contents = ' def callback (self,curl): self.contents = self.contents + curldef test_gzip (url): data = {} t = test () c = pycurl. Curl () c.setopt (pycurl. Writefunction,t.callback) c.setopt (pycurl. encoding, ' gzip ') c.setopt (pycurl. Url,url) &NBSP;&NBSP;&NBSp; c.perform () data[' HTTP_CODE ']=c.getinfo (c.HTTP_ CODE) data[' namelookup_time ']= (c.getinfo (c.namelookup_time)) *1000 data[' connect_time ']= (c.getinfo (c.connect_time)) *1000 data[' PRETRANSFER_TIME ']= ( C.getinfo (c.pretransfer_time)) *1000 data[' speed_download ']=c.getinfo (c.SPEED_DOWNLOAD) return datadef web_name_discovery (): web_list=[] web_dict={"data":none} for url in urllist: url_dict={} url_dict[ "{#NAME}"]=url web_list.append (url_dict) web_dict["data"]=web_list jsonstr = json.dumps (web_dict, sort_keys =true, indent=4) return jsonstrdef get_web_status (): data=test_gzip (sys.argv [2]) return data[sys.argv[3]]if __name__ == ' __main__ ': if sys.argv[1] == "web_name_discovery": print web_name_discovery () elif sys.argv[1] == "get_web_ Status ": print get_web_status ()</pre><p><p>2. The Web_name_discovery function is responsible for returning the domain name we want to monitor in JSON format (modify urllist to turn the domain name into your own domain): execution result:</p></p><pre class="brush:python;toolbar:false"><pre class="brush:python;toolbar:false">[[email protected] scripts]# python web_monitor.py web_name_discovery{"data": [{"{#NAME}": "www.ba idu.com "}, {" {#NAME} ":" www.hao123.com "}]}</pre></pre><p><p>* * This {#NAME} is the macro variable we want to return;</p></p><p><p><br></p></p><p><p>3. The web defines this key in anent and is defined in the Web Ui:</p></p><pre class="brush:python;toolbar:false"><pre class="brush:python;toolbar:false">[email protected] scripts]# cat/usr/local/zabbix/etc/zabbix_agentd.conf.d/web_status.conf userparameter=get_web_ name,/usr/local/zabbix/scripts/web_monitor.py web_name_discoveryuserparameter=get_web_status[*],/usr/local/ zabbix/scripts/web_monitor.py Get_web_status</pre></pre><p><p><br></p></p><p><p>Test Results:</p></p><p><p><br></p></p><pre class="brush:python;toolbar:false"><pre class="brush:python;toolbar:false">[[email protected] bin]#./zabbix_get-s 192.168.10.100-k get_web_name{"data": [{"{#NAME}": "www. Baidu.com "}, {" {#NAME} ":" www.hao123.com "}]}</pre></pre><p><p><br></p></p><p><p>Define the key for the Web UI (configure---template---create an Autodiscover rule---define the first key to get the name of the domain):</p></p><p><p><br></p></p><p><p>650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/84/8A/wKioL1eTkmDwJGJKAAAumJNDU8o976.png-wh_500x0-wm_3 -wmp_4-s_2443770619.png "title=" qq picture 20160723235028.png "alt=" wkiol1etkmdwjgjkaaaumjndu8o976.png-wh_50 "/></p></p><p><p><br></p></p><p><p><br></p></p><p><p>4. Function Get_web_status Get the value of each quality of the Website: view key setting Effect:</p></p><p><p>#./zabbix_get-s 192.168.10.100-k get_web_status[www.hao123.com,http_code]<br></p></p><p><p>200</p></p><p><p><br></p></p><p><p>5, so that the return value of the key to get the status also found, the rest is in the template to define the monitoring of the original and out of the diagram alarm monitoring is good:</p></p><p><p><br></p></p><p><p>650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/84/8A/wKiom1eTk_jxm13fAACc1V4JtiQ756.png-wh_500x0-wm_3 -wmp_4-s_1122187158.png "title=" qq picture 20160723235729.png "alt=" wkiom1etk_jxm13faacc1v4jtiq756.png-wh_50 "/></p></p><p><p><br></p></p><p><p>6, Monitoring Graphics prototype Settings:</p></p><p><p><br></p></p><p><p>650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/84/8A/wKiom1eTlNfQDeNRAABaBNn4VW4748.png-wh_500x0-wm_3 -wmp_4-s_2941386250.png "title=" qq picture 20160724000107.png "width=" 396 "height=" "border=" 0 "hspace=" 0 "vspace=" 0 " style= "width:396px;height:200px;" alt= "wkiom1etlnfqdenraababnn4vw4748.png-wh_50"/></p></p><p><p><br></p></p><p><p>7. Response time of each state of the website:</p></p><p><p><br></p></p><p><p>650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/84/8A/wKiom1eTmLqCttdMAAC69-65dzM449.png-wh_500x0-wm_3 -wmp_4-s_2713624523.png "title=" 1.png "alt=" wkiom1etmlqcttdmaac69-65dzm449.png-wh_50 "/></p></p><p><p><br></p></p><p><p>Average website Download speed:</p></p><p><p><br></p></p><p><p>650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/84/8A/wKioL1eTlTeCPHmLAACnQzSYjjI612.png-wh_500x0-wm_3 -wmp_4-s_1718435053.png "title=" qq picture 20160723235928.png "alt=" wkiol1etltecphmlaacnqzsyjji612.png-wh_50 "/></p></p><p><p><br></p></p><p><p>The status code of the Website:</p></p><p><p><br></p></p><p><p>650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/84/8A/wKiom1eTlVLxndZSAABjMa7Woeg717.png-wh_500x0-wm_3 -wmp_4-s_2354509298.png "title=" qq picture 20160723235911.png "alt=" wkiom1etlvlxndzsaabjma7woeg717.png-wh_50 "/></p></p><p><p><br></p></p><p><p>To this has been completed, the latter can do some optimization, or unexpected places you can modify: I use Zabbix 3.0, 3.0 words directly download template import, define angent key Can:</p></p><p><p><br></p></p><p style="padding:0px;margin-top:0px;margin-bottom:0px;clear:both;height:auto;color:rgb(44,44,44);font-family:‘宋体‘, ‘Arial Narrow‘, arial, serif;font-size:14px;line-height:28px;white-space:normal;background-color:rgb(255,255,255);"><p style="padding:0px;margin-top:0px;margin-bottom:0px;clear:both;height:auto;color:rgb(44,44,44);font-family:‘宋体‘, ‘Arial Narrow‘, arial, serif;font-size:14px;line-height:28px;white-space:normal;background-color:rgb(255,255,255);">Zabbix Video can be viewed:</p></p><p style="padding:0px;margin-top:0px;margin-bottom:0px;clear:both;height:auto;color:rgb(44,44,44);font-family:‘宋体‘, ‘Arial Narrow‘, arial, serif;font-size:14px;line-height:28px;white-space:normal;background-color:rgb(255,255,255);"><p style="padding:0px;margin-top:0px;margin-bottom:0px;clear:both;height:auto;color:rgb(44,44,44);font-family:‘宋体‘, ‘Arial Narrow‘, arial, serif;font-size:14px;line-height:28px;white-space:normal;background-color:rgb(255,255,255);">Http://www.roncoo.com/details?cid=fb3050a5b34b42f39ccad83ebebc89c1</p></p><p><p><br></p></p><p><p>This article is from the "little luo" blog, please be sure to keep this source http://xiaoluoge.blog.51cto.com/9141967/1829233</p></p><p><p>Zabbix LLD combined with Pycurl batch monitoring website service quality</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.