Before we have learned, how to collect some relevant data of the quality of the site service, and then through the warehousing out of the map, and began to plan to use RRDtool to do the drawing, but after a period of research, found that echarts out reasonable and beautiful, the following posted in my real-time collection of data and plot show part:
1, data collection, and format the form of a dictionary:
#!/usr/bin/env python
#-*-Coding:utf-8-*-
Import Os,sys,json
Import time
Import Sys
Import Pycurl
Class Test:
def __init__ (self):
self.contents = ' '
DEF callback (SELF,BUF):
self.contents = self.contents + buf
def test_gzip (Input_url):
data = {}
t = Test ()
c = Pycurl. Curl ()
C.setopt (Pycurl. Writefunction,t.callback)
C.setopt (Pycurl. ENCODING, ' gzip ')
C.setopt (Pycurl. Url,input_url)
C.perform ()
Namelookuptime = C.getinfo (c.namelookup_time)
Connecttime = C.getinfo (c.connect_time)
Pretransfertime = C.getinfo (c.pretransfer_time)
Starttransfertime = C.getinfo (c.starttransfer_time)
TotalTime = C.getinfo (c.total_time)
Httpcode = C.getinfo (C.http_code)
Sizedownload = C.getinfo (c.size_download)
Headersize = C.getinfo (c.header_size)
Speeddownload=c.getinfo (C.speed_download)
data["Httpcode"]= Httpcode
data["Namelookuptime"]= "%.2f"% (namelookuptime*1000)
data["Connecttime"]= "%.2f"% (connecttime*1000)
data["Pretransfertime"]= "%.2f"% (pretransfertime*1000)
data["Starttransfertime"]= "%.2f"% (starttransfertime*1000)
data["TotalTime"]= "%.2f"% (totaltime*1000)
data["Sizedownload"]= "%d"% (sizedownload)
data["headersize"] = "%d"% (headersize)
data["Speeddownload"]= "%d"% (speeddownload)
Print data
if __name__ = = ' __main__ ':
Input_url = sys.argv[1]
Test_gzip (Input_url)
2, back-end processing of data, formatted output:
def pycurl (Request):
cmd = "python%s/backend/pcurl.py www.shikee.com"% ('/yizhan/oms/app01 ')
data = Os.popen (cmd). Read ()
Data=eval (data) #这个函数害苦我了, the beginning of how to set the wrong, after the call eval done
Namelookuptime=float (data[' namelookuptime ')
Connecttime=float (data[' connecttime ')
Pretransfertime=float (data[' pretransfertime ')
Starttransfertime=float (data[' starttransfertime ')
Totaltime=float (data[' totaltime ')
Speeddownload=float (data[' speeddownload ')
Return Render_to_response (' pycurl.html ', {' namelookuptime ': namelookuptime, ' connecttime ': connecttime, ' Pretransfertime ':P retransfertime, ' starttransfertime ': starttransfertime, ' totaltime ': totaltime, ' SPEEDDOWNLOAD ': Speeddownload})
3, the plot of the small code:
var mychart = ec.init (document.getElementById (' main '));
var option = {
ToolTip: {
Show:true
},
Legend: {
data:[' www.shikee.com ']
},
Xaxis: [
{
Type: ' Category ',
Data: ["DNS Resolution Time", "Establish connection Time", "redirect Consumption time", "Transfer End Time", "Transfer end Time"]
}
],
YAxis: [
{
Type: ' Value '
}
],
Series: [
{
"Name": "Quality of Service map",
"Type": "Bar",
"Data": [{{namelookuptime}},{{connecttime}},{{pretransfertime}},{{starttransfertime}},{{totaltime}}]
}
]
};
4, out of:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/5A/22/wKiom1T3rTGx75VnAAEMLtnVfAY008.jpg "title=" Monitor the diagram. png "alt=" wkiom1t3rtgx75vnaaemltnvfay008.jpg "/>
The effect of today's show is here for the time being.
This article is from the "Little Luo" blog, please be sure to keep this source http://xiaoluoge.blog.51cto.com/9141967/1617461
Monitor the quality of the site service map after learning sequel