1. Detect Web Service quality (HTTP status code, request delay, HTTP header information, download speed, etc.)
Web Quality of Service: 1. Service availability
2. Service Response speed
2. Example
import os,sys import pycurlimport timeurl = "Http://www.baidu.com" # #目录的URLc = pycurl. Curl () # #实例化c. setopt (Pycurl. Url,url) # #定义请求的URL常量c. setopt (Pycurl. connecttimeout, 5) # #定义请求连接等待时间c. setopt (Pycurl. timeout, 5) # #定义请求超时时间c. setopt (Pycurl. noprogress, 1) # #屏蔽下载进度条c. setopt (Pycurl. forbid_reuse, 1) # #完成交互后强制断开连接, do not reuse c.setopt (Pycurl. maxredirs, 1) # #指定HTTP重定向的最大数为1c. setopt (Pycurl. dns_cache_timeout,30) # #设置保存DNS信息的时间为30Sindexfile = open (Os.path.dirname ( Os.path.realpath (__file__)) + "/content.txt", "WB") c.setopt (Pycurl. Writeheader, indexfile) # #将返回的HTTP header directed to Indexfilec.setopt (Pycurl. Writedata, indexfile) # #将返回的HTML内容定向到indexfile文件对象try: C.perform () # #提交请求except Exception,e: print "error" indexfile.close () sys.exit () Namelookup_time = c.getinfo (c.NAMELOOKUP_ Time) # #获取DNS解析时间CONNECT_TIME = c.getinfo (c.connect_time) ## Get Establish Connection time Pretransfer_time = c.getinfo (c.pretransfer_time) ## Gets the time from establishing the connection to preparing the transfer Starttransfer_time = c.getinfo (c.starttransfer_time) # #获取从建立连接到传输开始需要时间TOTAL_TIME = c.getinfo (c.total_time) # #获取传输的总时间HTTP_CODE = c.getinfo (c.http_code) # #获取HTTP状态码SIZE_DOWNLOAD = c.getinfo (c.size_download) # #获取下载数据包大小HEADER_SIZE = c.getinfo (c.header_size) # #获取HTTP头部大小SPEED_DOWNLOAD = c.getinfo (c. Speed_download) # #获取平均下载速度print "HTTP status code:%s " %HTTP_CODEprint "DNS resolution time:%.2f ms " % (namelookup_time*1000) print " Established connection time:%.2f MS " % (connect_time*1000) print " Ready to transfer time:%.2f ms " % (pretransfer_time*1000) print " Transfer start time: %2.f ms " % (starttransfer_time*1000) print " Total time to transfer: %.2f ms " %" _time*1000) print "Download packet size: %d bytes/s" % (size_download) print "HTTP header size: %d Byte " % (header_size) print " average download speed:%d bytes/s "% (speed_download) indexfile.close () ## Close File C.close () # #关闭Curl对象
Test
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/A6/F0/wKioL1nd-hnRdwd4AAB7f2BkHTM734.png "title=" Screenshot from 2017-10-11 19-12-59.png "alt=" Wkiol1nd-hnrdwd4aab7f2bkhtm734.png "/>
Python automated operation and maintenance Pycurl