Jenny jmeter based on distributed small python's

jmeter distributed stress tests: the so-called distributed, namely as a control unit, to control other machines with multiple load to run our test script, the final pressure on our test system

This issue python script to achieve:

1. Read the configuration table from excel execution times, the number of threads, IP and port, etc.

IP port, load machine:: Path 2. splicing command jmeter -n -t jmx script -R load machine ip start time variable on the number of threads set in the script variables -J -J script set in the port -l test The results path -e -o test html report path

E.g:

jmeter -n -t .\jmeter_script\TCtestcase_xn\TC_testscript.jmx -R10.5.32.XX:1099,10.5.32.XX:1099 -Jthread_num=30 -Jrunup_time=2 -Jrun_time=10 -l .\test_result\test_jtl\test2019-11-27-11-36-24.jtl -e -o .\test_result\test_html\HTML2019-11-27-11-36-24

One: Preparing the Environment

Environment: linux server

Control machine load machine: both for Windows  

To ensure that: the control unit and the load unit in the same network segment, i.e. the top three IP requires the same, the request can ping each other

Preparing the environment:

JDK 1. Load control unit and installation of the same version (Version 1.8 and above) and the same version of jmeter, preferably placed in the same path

2. The load machine and a control unit configured jmeter the environment variable JDK

3. environment variable configuration is complete, enter cmd: java -version be able to view the JDK version, type in cmd: jmeter can open jmeter correctly, the configuration was successful environment

4. placed in the same directory control machines and load machine test scripts to run, the script as quoted CSV file, you need to write absolute path, or operating results will be empty

Control machine modification:

1. Modify the following jmeter directory bin / jmeter.properties file:

REMOTE_HOST: Fill IP load machine can be more than, ports 1099 are, in the format ip: port, IP: port, ip: port Note: the control unit can also be used as a load machine, and fill ip dynamometer port,

server_port: Fill 1099

 

 

 

Continue to modify the contents of this document are as follows: 

server.rmi.ssl.disable=true

language=zh_CN

jmeter.save.saveservice.label=true

jmeter.save.saveservice.response_code=true

jmeter.save.saveservice.response_data=true

jmeter.save.saveservice.response_message=true
jmeter.save.saveservice.successful=true
jmeter.save.saveservice.thread_name=true
jmeter.save.saveservice.time=true

jmeter.save.saveservice.latency=true

jmeter.save.saveservice.samplerData=true
jmeter.save.saveservice.responseHeaders=true

jmeter.save.saveservice.bytes=true

jmeter.save.saveservice.thread_counts=true

jmeter.save.saveservice.timestamp_format=ms
jmeter.save.saveservice.timestamp_format=yyyy/MM/dd HH:mm:ss.SSS

sampleresult.timestamp.start=true

Load machine modification:

1. Modify the following jmeter directory bin / jmeter.properties file:

server.rmi.ssl.disable=true

Second, script execution

1. All dynamometer open jmeter directory bin / jmeter-server.bat file (right-administrator opens)

cmd window that opens showed ip and port of the machine

 

 

 2. Run the script in cmd 

 IP port, load machine:: Path jmeter -n -t jmx script -R load machine ip start time variable on the number of threads set in the script variables -J -J port script set in the path -e -l test results -o test html report path

Should pay attention to when you run the command a second time to change the name jtl results file and test reports, otherwise the result will be superimposed jtl, html file will be prompted to repeat or directory is not empty


3. Run the script every time you need to modify the file because the name is very inconvenient, all integrated with the python script that generates test results and test report different names each dynamic in cmd

Specific python code is as follows:

This code implementation:

1. In a number of threads required to excel sheet filled manually, start time, execution time, execution number of machines, machine control ip and port

2.python script reads the Excel file

3. jmeter script by aide Tools-- function, select __p functions, variables generated by the steps in the chart, primarily calling for the late order to avoid the need to open each time you run scripts to modify these parameters jmeter

 

 

 

 

 

 

 

 

3. Configure the number of threads to run in our Excel, the number of start-up time, execution time, execution machine, IP port

4.python script to read more of Excel, and then spliced ​​into a command, and then execute the command

 

 

 


import os
import time
from openpyxl import load_workbook
#读取配置的excel
wb = load_workbook(r".\test_plan\pressure_schedule.xlsx")
sheet = wb.worksheets[0]
row = sheet.max_row
column = sheet.max_column
def file_msg():
for i in range(row-1):
thread_info = sheet.cell(i + 2, 3).value
runup_info = sheet.cell(i + 2, 4).value
time_info = sheet.cell(i + 2, 5).value
ip_num = sheet.cell(i + 2, 6).value
now = time.strftime("%Y-%m-%d-%H-%M-%S")
ip_msg1 = ""
for m in range(ip_num):
ip = sheet.cell(i + 2, 7 + int(m) * 2).value
port = sheet.cell(i + 2, 8 + int(m) * 2).value
str_msg = str(ip)+":"+str(port)
ip_msg1 = ip_msg1+str_msg+","
ip_msg2 = " -R"+ip_msg1
ip_msg = ip_msg2[:-1]
print(ip_msg)
#拼接jmeter命令
exect = "jmeter -n -t "\
+ r".\jmeter_script\TCtestcase_xn\TC_testscript.jmx"\
+ip_msg\
+" -Jthread_num="+str(thread_info)+" -Jrunup_time="+str(runup_info)\
+" -Jrun_time="+str(time_info)+" -l "\
+r".\test_result\test_jtl\test"+now+".jtl"\
+ r" -e -o "+r".\test_result\test_html\HTML" +now
#执行命令
    os.system(exect)

print(exect)
wb.close()
#调用该方法
file_msg()

Guess you like

Origin www.cnblogs.com/xiaozhenzhen/p/11941168.html