监控网站服务质量出图学习后续篇
作者:网络转载 发布时间:[ 2015/8/20 15:02:27 ] 推荐标签:软件测试管理
前面我们已经学习过了,如何收集网站服务质量的一些相关数据,然后通过入库出图,开始打算是用rrdtool做画图,但是经过一段时间的研究,发现echarts出图合理和美观,下面贴出我实时收集到的数据和出图展示部分:
1、数据收集,并且格式化形成字典:
#!/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)
return data
if __name__ == '__main__':
input_url = sys.argv[1]
print test_gzip(input_url)
2、后端处理数据,格式化输出:
def pycurl(request):
cmd = "python %s/backend/pcurl.py www.shikee.com" %('/yizhan/oms/app01')
data = os.popen(cmd).read()
data=eval(data) #这个函数害苦我了,开始怎么设置都不对,调用eval之后搞定
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':PRETRANSFERTIME,'STARTTRANSFERTIME':STARTTRANSFERTIME,'TOTALTIME':TOTALTIME,'SPEEDDOWNLOAD':SPEEDDOWNLOAD})
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11