Jmeter is a good performance testing tool, and free of charge, but one problem is that the tool does not have its own timing auto-test function. What if I have to press one at 11 o'clock? So i found ant, and there was a corresponding jmetertask. with the crontab function on linux , we can realize the test of timing automation performance!
Tool Preparation:
JDK http://www.oracle.com/technetwork/java/javase/downloads/index.html
Jmeter http://jmeter.apache.org/
Ant http://ant.apache.org/
Environment Preparation:
In order to use the crontab, the environment is built on the Linux server.
To set the ant environment variable:
Vim/etc/profile
Enter edit mode, at the end of the input
Export Ant_home= "/home/apache-ant-1.9.7" (ANT Tool Absolute path)
Export path= "/home/apache-ant-1.9.7/bin": $PATH (Bin Absolute path )
After saving and exiting, run the command
Source/etc/profile
Next check to see if the environment is well built
Java Environment Check
Jmeter Environment
ANT Environment
Above, three environments have been built!
Locate the ant-jmeter-1.1.1.jar file in the Extras subdirectory in the directory where JMeter is located , and copy it to Ant Location Directory Lib Sub-directory.
Edit build.xml(emphasis)
Create a new XML file with the following contents:
1<?xml version="1.0"encoding="UTF-8"?>2 3<project name="ant-jmeter-test" default="Run"Basedir=".">4<tstamp>5<format property=" Time"pattern="yyyymmddhhmm"/>6</tstamp>7<!--need to change to their local Jmeter directory--8<property name="Jmeter.home"Value="H:\apache-jmeter-2.12"/>9<!--jmeter Generate JTL Format Results report path--Ten<property name="Jmeter.result.jtl.dir"Value="H:\APACHE-JMETER-2.12\REPORT\JTL"/> One<!--JMeter generates a path to the results report in HTML format-- A<property name="Jmeter.result.html.dir"Value="H:\apache-jmeter-2.12\report\html"/> -<!--generated report prefixes-- -<property name="ReportName"Value="Testreport"/> the<property name="Jmeter.result.jtlName"Value="${JMETER.RESULT.JTL.DIR}/${REPORTNAME}${TIME}.JTL"/> -<property name="Jmeter.result.htmlName"Value="${jmeter.result.html.dir}/${reportname}${time}.html"/> - -<target name="Run"> +<antcall target="Test"/> -<antcall target=" Report"/> +</target> A at<target name="Test"> -<taskdef name="JMeter"Classname="Org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/> -<jmeter jmeterhome="${jmeter.home}"resultlog="${jmeter.result.jtlname}"> -<!--declare the script to run."*.JMX"Refers to all JMeter scripts that contain this directory-- -<testplans dir="H:\apache-jmeter-2.12\testcase"includes="*.JMX"/> - in<property name="Jmeter.save.saveservice.output_format"Value="XML"/> - to</jmeter> +</target> -<path id="Xslt.classpath"> the<fileset dir="${jmeter.home}/lib"includes="Xalan*.jar"/> *<fileset dir="${jmeter.home}/lib"includes="Serializer*.jar"/> $</path>Panax Notoginseng - the<target name=" Report"> +<XSLT Aclasspathref="Xslt.classpath" theForce="true" + inch="${jmeter.result.jtlname}" - out="${jmeter.result.htmlname}" $style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl"/> $<param name="Datereport"expression="${report.datestamp}"/> -</xslt> - the<!--because when the report is generated, the associated pictures are not copied to the target directory, so you need to manually copy-- -<copy todir="${jmeter.result.html.dir}">Wuyi<fileset dir="${jmeter.home}/extras"> the<include name="Collapse.png"/> -<include name="Expand.png"/> Wu</fileset> -</copy> About</target> $</project>
According to the contents of the comments modified, the basic format is not a problem, run based on error to find related errors
, remember to save the utf-8 encoded format when saving. Place the build.xml file in the ant bin directory.
operations on the Jmeter :
First on the jmeter to determine the jmx file is operational, will not error.
Operations on a Linux server:
Prevent service from being opened, first
Chmod 777 Build.xml
Then go to the directory to run the Ant program and test start!
The result is a successful test. You can go to the target path to open the test results HTML directly to view.
If you see this error
error! Content is not allowed in Prolog.
error! Com.sun.org.apache.xml.inernal.utils.WrappedRuntimeException:Content isn't allowed in Prolog
There is a long list of mistakes to be added at the bottom of the build.xml .
<property name= "Jmeter.save.saveservice.output_format" value= "xml"/> just fine, this is a file format problem. (already added in the code above)
To set the timer function:
setting crontab on a Linux server
Command crontab-e
Enter edit mode to set timer content
0 * */home/apache-ant-1.9.7/bin/ant-file/home//apache-ant-1.9.7/bin/build.xml
The time is 5 digits for the minute hour date month week (Baidu time setting in Linux)
Follow the absolute path to the application you want to run
follow the absolute path to the configuration file after -file
The above time for each month of the night to start the program, the next day to the results of the report folder to take the results of the evening test to see it!
Error a bit more haha, you can report to the development!
For the principle that the last min and Max time cannot be viewed, refer to this article of the Great God
Http://www.cnblogs.com/puresoul/p/5053035.html
Ant+jmeter for automated performance testing