Skip to content

Commit 3157a0c

Browse files
author
qtracer
committed
报告、代码优化
1 parent 5358bf8 commit 3157a0c

File tree

8 files changed

+144
-20
lines changed

8 files changed

+144
-20
lines changed

func/cvfTarCode.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ JOB_NAME=$2
55

66

77
echo $0
8-
tar zcvf ${packageName}.tar $(ls | grep "${JOB_NAME}$")
8+
tar zcvf ${packageName}.tar $(ls | grep "${JOB_NAME}$") > /dev/null
99

1010
project_path=$(cd `dirname $0`; pwd)
1111
project_name="${project_path##*/}"

func/transportFilesAndInitWorker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ expect -c "
5050
expect -re {\\$|#} {send \"sudo chmod 775 ${locustlog}/${projectPackage}/$(date +%Y%m%d)\n\"}
5151
expect -re {\\$|#} {send \"sudo chown -R ${account}:${account} ${locustlog}/${projectPackage}/$(date +%Y%m%d)\n\"}
5252
expect -re {\\$|#} {send \"cd ${targetDir}\n\"}
53-
expect -re {\\$|#} {send \"sudo tar zxvf ${sourceDir}${sn}.tar\n\"}
53+
expect -re {\\$|#} {send \"sudo tar zxvf ${sourceDir}${sn}.tar > /dev/null\n\"}
5454
expect -re {\\$|#} {send \"cd ${locust_workspace} && sudo rm -rf ${projectPackage} && sudo mv ${targetDir}/${sourceDir}${sn}/${projectPackage} ${locust_workspace}\n\"}
5555
expect -re {\\$|#} {send \"sudo rm -rf ${targetDir}/${shellPackage} && sudo mv ${targetDir}/${sourceDir}${sn}/${shellPackage} ${targetDir} \n\"}
5656
expect -re {\\$|#} {send \"sudo rm -rf ${targetDir}/${sourceDir}${sn}* \n\"}

func/xvfTarCode.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ bash ${workdir}/comm/echoInfo.sh $workdir
99

1010
function xvfCodePackage(){
1111
package=$1
12-
tar zxvf ${package}.tar $(ls | grep "${package}$")
12+
tar zxvf ${package}.tar $(ls | grep "${package}$") > /dev/null
1313
}
1414

1515
echo "xvfTarCode.sh, pwd is: $(pwd)"

func/z_installPython3.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function installPy(){
1717
cd ${jenkins_home}/python3
1818
wget http://python.org/ftp/python/${pyVersion}/Python-${pyVersion}.tgz --no-check-certificate
1919
sleep 1s
20-
tar -zxvf Python-${pyVersion}.tgz
20+
tar -zxvf Python-${pyVersion}.tgz > /dev/null
2121
sleep 2s
2222
fi
2323
}

ini/config.ini

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,19 @@ registry_postgresql=
5757
registry_sonarqube=
5858
registry_jenkins=
5959

60+
[apitimeout]
61+
# 针对locust压测报告90%、95%超时(毫秒)API的数量统计
62+
api_90timeout=500
63+
api_95timeout=500
64+
6065
[cron]
6166
# seconds
6267
locust_sendreport_wait=2
6368
# 提供定时任务终止机制,当flag=0,days所有定时任务程序均终止
6469
global_wait_flag=1
6570
# 避免master节点每次执行main-cli.sh都生成任务,slave节点只有在initNodes才会生成
6671
master_cronExist_flag=0
67-
# days
72+
# days, wait周期检测时间; interval过期删除
6873
hrun_log_wait=1
6974
hrun_log_interval=3
7075
hrun_container_wait=1

python/sendHrunReport.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def reportElementHandle(wfile):
3131
# time
3232
startat=alltd[0].text
3333
duration=alltd[1].text
34-
dic['startat']=startat
34+
dic['startat']=startat.split(".")[0]
3535
dic['duration']=duration
3636

3737
## testcases
@@ -119,15 +119,15 @@ def send_email(subject, dicbody, file=None):
119119
</tr>
120120
<tr>
121121
<th style="font-weight: bold;font-size: 15px;">Start At</th>
122-
<td colspan="4",style="font-size: 15px;">{dicbody['startat']}</td>
122+
<td colspan="4",style="font-size: 15px;">{dicbody['startat']}+00:00</td>
123123
</tr>
124124
<tr>
125125
<th style="font-weight: bold;font-size: 15px;">Duration</th>
126126
<td colspan="4",style="font-size: 15px;">{dicbody['duration']}</td>
127127
</tr>
128128
<tr>
129129
<th style="font-weight: bold;font-size: 15px;">Tips</th>
130-
<td colspan="4", style="font-size: 15px;">.:suc / F:fail / E:err / s:skip</td>
130+
<td colspan="4", style="font-size: 15px;">.>suc / F>fail / E>err / s>skip</td>
131131
</tr>
132132
</table>
133133
<table style="width: 100%; margin:auto">

python/sendLocustReports.py

Lines changed: 130 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
file.write(down_res.content)
2525
file.close()
2626

27+
'''获取ini/config.ini的邮件配置信息'''
28+
def getConfig(section, key):
29+
cf.read(cfp, encoding="utf8")
30+
value = cf.get(section, key)
31+
return value
32+
33+
2734
'''截取HTML测试报告关键信息'''
2835
def reportElementHandle(wfile):
2936
# 读取HTML文件
@@ -32,19 +39,53 @@ def reportElementHandle(wfile):
3239

3340
# 使用BeautifulSoup解析HTML
3441
soup = BeautifulSoup(html_content, 'lxml')
42+
dic = {}
43+
timeoutAPI90 = 0
44+
timeoutAPI95 = 0
45+
failAPI = 0
46+
47+
# 读取config.ini API超时设置
48+
api_90timeout = int(getConfig('apitimeout', 'api_90timeout'))
49+
api_95timeout = int(getConfig('apitimeout', 'api_95timeout'))
3550

51+
## HTML-info
3652
summ = soup.find(class_='info')
3753
allspan = summ.find_all('span')
38-
dic = {}
3954
dic['starttime']=allspan[0].text
4055
dic['endtime'] = allspan[1].text
56+
dic['host'] = allspan[2].text
57+
58+
## HTML-requests
59+
rq = soup.find(class_='requests')
60+
alltd = rq.find_all('td')
61+
dic['total RPS'] = alltd[-2].text
62+
dic['Failures/s'] = alltd[-1].text
63+
64+
alltr = rq.find('tbody').find_all('tr')
65+
dic['API Amount'] = len(alltr) - 1
66+
for tr in alltr:
67+
alltd = tr.find_all('td')
68+
if int(alltd[3].text) > 0:
69+
failAPI += 1
70+
# 去掉聚合td的统计
71+
if failAPI > 0:
72+
failAPI -= 1
73+
dic['failAPIs'] = failAPI
74+
75+
## HTML-responses
76+
rs = soup.find(class_='responses')
77+
alltr = rs.find('tbody').find_all('tr')
78+
for tr in alltr:
79+
alltd = tr.find_all('td')
80+
if int(alltd[6].text) > api_90timeout:
81+
timeoutAPI90 += 1
82+
if int(alltd[7].text) > api_95timeout:
83+
timeoutAPI95 += 1
84+
dic['90timeoutAPIs'] = timeoutAPI90
85+
dic['95timeoutAPIs'] = timeoutAPI95
86+
4187
return dic
4288

43-
'''获取ini/config.ini的邮件配置信息'''
44-
def getConfig(section, key):
45-
cf.read(cfp, encoding="utf8")
46-
value = cf.get(section, key)
47-
return value
4889

4990
'''发送邮件'''
5091
def send_email(subject, dicbody, file=None):
@@ -57,15 +98,93 @@ def send_email(subject, dicbody, file=None):
5798

5899
# 创建 MIMEMultipart 对象
59100
# 邮件三个头部信息
60-
mail = MIMEMultipart()
101+
mail = MIMEMultipart('alternative')
61102
mail['Subject'] = subject
62103
mail['From'] = sender
63104
mail['To'] = ",".join(receiver)
64105

65-
starttime=dicbody['starttime']
66-
endtime=dicbody['endtime']
67-
bodytext=f"starttime:{starttime}GMT\nendtime:{endtime}GMT\n详细见附件"
68-
mail.attach(MIMEText(bodytext, 'plain', 'utf-8'))
106+
# HTML内容
107+
if float(dicbody['Failures/s']) > 0:
108+
color_Failures = "red"
109+
else:
110+
color_Failures = "green"
111+
112+
if dicbody['failAPIs'] > 0:
113+
color_failAPIs = "red"
114+
else:
115+
color_failAPIs = "green"
116+
117+
if dicbody['90timeoutAPIs'] > 0:
118+
color_90timeoutAPIs = "red"
119+
else:
120+
color_90timeoutAPIs = "green"
121+
122+
if dicbody['95timeoutAPIs'] > 0:
123+
color_95timeoutAPIs = "red"
124+
else:
125+
color_95timeoutAPIs = "green"
126+
127+
html_content = f"""
128+
<!DOCTYPE html>
129+
<html lang="en">
130+
<head>
131+
<meta charset="UTF-8">
132+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
133+
<title>Email Example</title>
134+
</head>
135+
<body>
136+
<table id="summary", style="width: 100%; margin:auto">
137+
<tr>
138+
<th style="font-weight: bold;font-size: 15px;">Host</th>
139+
<td colspan="4",style="font-size: 15px;">{dicbody['host']}</td>
140+
</tr>
141+
<tr>
142+
<th style="font-weight: bold;font-size: 15px;">StartTime</th>
143+
<td colspan="4",style="font-size: 15px;">{dicbody['starttime']}+00:00</td>
144+
</tr>
145+
<tr>
146+
<th style="font-weight: bold;font-size: 15px;">EndTime</th>
147+
<td colspan="4",style="font-size: 15px;">{dicbody['endtime']}+00:00</td>
148+
</tr>
149+
<tr>
150+
<th style="font-weight: bold; color: orange;font-size: 17px;">RPS</th>
151+
</tr>
152+
<tr>
153+
<th style="font-weight: bold;font-size: 15px;">Totals</th>
154+
<td colspan="4",style="font-weight: bold; font-size: 17px; color: green;">{dicbody['total RPS']}</td>
155+
</tr>
156+
<tr>
157+
<th style="font-weight: bold;font-size: 15px;">Failures</th>
158+
<td colspan="4",style="font-weight: bold; font-size: 17px; color: {color_Failures};">{dicbody['Failures/s']}</td>
159+
</tr>
160+
<tr>
161+
<th style="font-weight: bold; color: orange;font-size: 17px;">APIs</th>
162+
</tr>
163+
<tr>
164+
<th style="font-weight: bold;font-size: 15px;">Totals</th>
165+
<td colspan="4",style="font-size: 15px;">{dicbody['API Amount']}</td>
166+
</tr>
167+
<tr>
168+
<th style="font-weight: bold;font-size: 15px;">Failures</th>
169+
<td colspan="4",style="font-size: 15px; font-weight: bold; color: {color_failAPIs};">{dicbody['failAPIs']}</td>
170+
</tr>
171+
<tr>
172+
<th style="font-weight: bold; font-size: 15px;">90%Tout</th>
173+
<td colspan="4",style="font-size: 15px; font-weight: bold; color: {color_90timeoutAPIs};">{dicbody['90timeoutAPIs']}</td>
174+
</tr>
175+
<tr>
176+
<th style="font-weight: bold;font-size: 15px;">95%Tout</th>
177+
<td colspan="4",style="font-size: 15px; font-weight: bold; color: {color_95timeoutAPIs};">{dicbody['95timeoutAPIs']}</td>
178+
</tr>
179+
</table>
180+
</body>
181+
</html>
182+
"""
183+
mail.attach(MIMEText(html_content, 'html'))
184+
185+
# # 纯文本
186+
# bodytext = f"failAPIs:\n {dicbody['failAPIs']}\n timeoutAPIs:\n {dicbody['timeoutAPIs']}"
187+
# mail.attach(MIMEText(bodytext, 'plain', 'utf-8'))
69188

70189
# 附件
71190
att1 = MIMEText(open(file, 'rb').read(), 'html', 'utf-8')

views/initNodes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ do
6262
expect -re {\\$|#} {send \"cd ${targetDir} \n\"}
6363
expect -re {\\$|#} {send \"sudo mkdir -vp ${targetDir}/${shellPackage} \n\"}
6464
expect -re {\\$|#} {send \"sudo rm -rf ${shellPackage}/ \n\"}
65-
expect -re {\\$|#} {send \"sudo tar zxvf ${shellPackage}.tar \n\"}
65+
expect -re {\\$|#} {send \"sudo tar zxvf ${shellPackage}.tar > /dev/null \n\"}
6666
expect -re {\\$|#} {send \"sudo rm -f ${targetDir}/${shellPackage}.tar \n\"}
6767
expect -re {\\$|#} {send \"cd ${targetDir}/${shellPackage} \n\"}
6868
expect -re {\\$|#} {send \"sudo bash func/setGlobal.sh ${targetDir}/${shellPackage} \n\"}

0 commit comments

Comments
 (0)