Web monitoring: Zabbix automatically discovers +python's Pycur module on website Access quality monitoring

Source: Internet
Author: User
Tags python script

One:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/76/24/wKiom1ZLJ6PhCARDAAUWs8pXNuc408.jpg "style=" float: none; "title=" 1sunday.jpg "alt=" Wkiom1zlj6phcardaauws8pxnuc408.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/76/21/wKioL1ZLJ_nDj1jwAATQJ4Tmzok200.jpg "style=" float: none; "title=" 1qqtime.jpg "alt=" Wkiol1zlj_ndj1jwaatqj4tmzok200.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/76/24/wKiom1ZLJ6uyjgZoAARuTXFk0S0881.jpg "style=" float: none; "title=" 1qqtime1.jpg "alt=" Wkiom1zlj6uyjgzoaarutxfk0s0881.jpg "/>

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/76/24/wKiom1ZLJ7PjdgwKAAXhCOMawWo018.jpg "style=" float: none; "title=" 1time.jpg "alt=" Wkiom1zlj7pjdgwkaaxhcomawwo018.jpg "/>



Ii. Description of requirements:

Recently needs to the node to the source station, the office environment Access Business Platform website Quality and the office network Line quality monitoring, the simple ping can detect some things, but the HTTP request examination also must carry on, therefore studied the next pycurl.

Pycurl is a C language written by the Libcurl Python binding library. Libcurl is a free and easy-to-use URL transfer library that is used in the client. It's very powerful, and Pycurl is a very fast (reference multi-concurrency operation) and rich full-featured, but somewhat complex interface.

Third, Python script:

1. Writing httptime.py Scripts

Command VI zabbix_agentd.conf.d/httptime.py

#!/usr/bin/python

# Coding:utf-8

Import Pycurl

Import Sys

Import OS

Import JSON


Class Test:

def __init__ (self):

self.contents = ' '

def body_callback (SELF,BUF):

self.contents = self.contents + buf

def web_performance (Input_url,mykey):

t = Test ()

c = Pycurl. Curl ()

C.setopt (Pycurl. Writefunction,t.body_callback)

C.setopt (Pycurl. ENCODING, ' gzip ')

C.setopt (Pycurl. Url,input_url)

C.perform ()

if MyKey = = "Namelookup_time":

#DNS解析时间ms

Namelookup_time = C.getinfo (c.namelookup_time)

Print "%.2f"% (namelookup_time*1000)

#return MyKey

elif MyKey = = "Connect_time":

#建立连接时间ms

Connect_time = C.getinfo (c.connect_time)

Print "%.2f"% (connect_time*1000)

#return MyKey

elif MyKey = = "Pretransfer_time":

#准备传输时间ms

Pretransfer_time = C.getinfo (c.pretransfer_time)

Print "%.2f"% (pretransfer_time*1000)

#return MyKey

elif MyKey = = "Starttransfer_time":

#传输开始时间ms

Starttransfer_time = C.getinfo (c.starttransfer_time)

Print "%.2f"% (starttransfer_time*1000)

#return MyKey

elif MyKey = = "Total_time":

#传输结束总时间ms

Total_time = C.getinfo (c.total_time)

Print "%.2f"% (total_time*1000)

#return MyKey

elif MyKey = = "Size_download":

#下载数据包大小bytes/S

Size_download = C.getinfo (c.size_download)

Print "%d"% (size_download)

#return MyKey

elif MyKey = = "Header_size":

#HTTP头部大小bytes

Header_size = C.getinfo (c.header_size)

Print "%d"% (header_size)

#return MyKey

elif MyKey = = "Speed_download":

#平均下载速度bytes/S

Speed_download=c.getinfo (C.speed_download)

Print "%d"% (speed_download)

#return MyKey


Def web_discovery ():

Website = [' www.qq.com ', ' www.sina.com ', ' sunday208.blog.51cto.com '];

devices = []

For Devpath in website:

device = Os.path.basename (Devpath)

Devices + = [{' {#SITENAME} ':d Evice}]

Print json.dumps ({' Data ':d evices},sort_keys=true,indent=7,separators= (', ', ': '))


if __name__ = = ' __main__ ':

If sys.argv[1] = = "Web_discovery":

Web_discovery ()

If sys.argv[1] = = "Web_performance":

Input_url = sys.argv[2]

MyKey = sys.argv[3]

Web_performance (Input_url,mykey)


2. Plus Execute permissions:

Command chmod +x zabbix_agentd.conf.d/httptime.py


3. Apply to Zabbix Client configuration:

Command Tail-1 zabbix_agentd.conf

userparameter=http_curl[*],python/opt/soft/zabbix/etc/zabbix_agentd.conf.d/httptime.py $ $


4. Restart the Zabbix client:

/etc/init.d/zabbix_agentd restart


5, the service side test:

The command is as follows:

Zabbix_get-s 192.168.2.32-p 10050-k "Http_curl[web_discovery]"

Zabbix_get-s 192.168.2.32-p 10050-k "Http_curl[web_performance,www.qq.com,total_time]"

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/76/22/wKioL1ZLKFnRpd7cAAEtnacA3n4791.jpg "title=" 3zabbix_server_t.jpg "alt=" Wkiol1zlkfnrpd7caaetnaca3n4791.jpg "/>


Iv. Web Interface configuration:

1. After downloading the attachment template file (Web Access quality monitoring. xml), import it into Zabbix.

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/76/22/wKioL1ZLKG3D2EsyAAGaRlQvMlU749.jpg "title=" 4web_ 1.jpg "alt=" Wkiol1zlkg3d2esyaagarlqvmlu749.jpg "/>

2, the relevant configuration items in the template display:

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M01/76/22/wKioL1ZLKKDjsOy3AAIgaUD6vKs253.jpg "style=" float: none; "title=" 4web_2.jpg "alt=" Wkiol1zlkkdjsoy3aaigaud6vks253.jpg "/>

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/76/24/wKiom1ZLKFLhS_BzAAVVAZNWDHQ062.jpg "style=" float: none; "title=" 4web_3.jpg "alt=" Wkiom1zlkflhs_bzaavvaznwdhq062.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/76/22/wKioL1ZLKKiCDECVAAOAFWbAvNs504.jpg "style=" float: none; "title=" 4web_4.jpg "alt=" Wkiol1zlkkicdecvaaoafwbavns504.jpg "/>

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M02/76/22/wKioL1ZLKKnhrPJ2AAIakHGsJP8102.jpg "style=" float: none; "title=" 4web_5.jpg "alt=" Wkiol1zlkknhrpj2aaiakhgsjp8102.jpg "/>


3. Create a host and link the template

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M02/76/24/wKiom1ZLKHTBNyzrAAIXj18MkOA720.jpg "title=" 4web_ 6.jpg "alt=" Wkiom1zlkhtbnyzraaixj18mkoa720.jpg "/>

4. Data display

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M00/76/24/wKiom1ZLKIaAQF7IAAdqObgK2Qc378.jpg "title=" 4web_ 7.jpg "alt=" Wkiom1zlkiaaqf7iaadqobgk2qc378.jpg "/>



Lazy people use lazy methods.

Write Python for the first time, if you have any questions, please correct them in time.

This article is from the "Urban Cloth" blog, please be sure to keep this source http://sunday208.blog.51cto.com/377871/1713823

Web monitoring: Zabbix automatically discovers +python's Pycur module on website Access quality monitoring

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.