Jmeter study notes (1) installation and startup

1. jmeter installation on Linux

In order to facilitate the operation of jmeter, this article uses a Linux press and a Mac computer. ijmeter needs to be installed on both devices. The jmeter version and plug-in status need to be consistent.

Convenient version migration: In order to ensure that the jmeter version and plug-in installation of the debugging script and the actual running script are consistent, the entire jmeter package on the mac can be uploaded to the linux press for decompression.

1.1. Check java version

The operation of jmeter needs to be based on the java environment. You can use the following method to check whether the JDK has been installed on the current Linux system.

java -version

The result is as shown below. The Linux system has installed version 1.8 JDK:
Insert image description here

1.2. Upload Jmeter to Linux

As mentioned above, upload the Linux package on mac to the Linux system and decompress it. JMeter on the mac system needs to ensure that all plug-ins required for stress testing have been installed. If jmeter on mac makes plug-in changes and applies the newly installed plug-in to the script, but jmeter on Linux does not install the plug-in, the script may fail to be uploaded to Linux.

You can use the lrzsz command or Xterm tool to upload.

In the picture below, jmeter has been uploaded to Linux and decompressed successfully. Since the uploaded file is a zip archive, use the unzip command to decompress it.

unzip apache-jmeter-5.4.3.zip

Insert image description here

1.3. Configure environment variables

This step is to use the jmeter command more conveniently and can be omitted. The difference is that after configuring jmeter, you can directly execute the jmeter command in any directory to start the program. If you do not configure jmeter, you need to go to the installation path of jmeter (in the bin directory). ) executes the executable program of jmeter. For example, the jmeter installation path in this article is /root/tcmipresstest/apache-jmeter-5.4.3/bin. If it is not configured, you need to execute jmeter./root/tcmipresstest/apache-jmeter-5.4.3/bin/jmeter. . In short, configuring is more convenient than not configuring, and configuring is recommended.

Execute the following command to open the configuration file:

vi /etc/profile

After opening the configuration file, enter "i" to enter insert editing mode. Insert the following content into the file:

export JMETER_HOME=/root/tcmipresstest/apache-jmeter-5.4.3
export CLASSPATH=$JMETER_HOME/lib/ext/ApacheJMeter_core.jar:$JMETER_HOME/lib/jorphan.jar:$JMETER_HOME/lib/logkit-2.0.jar:$CLASSPATH
export PATH=$JMETER_HOME/bin:$PATH:$HOME/bin

The content of the JMETER_HOME variable is the absolute path of the jmeter installation directory (actually the folder path after decompression above). As mentioned above, my installation directory is /root/tcmipresstest/apache-jmeter-5.4.3. This path needs to be replaced according to the actual situation.
After modification, use "esc" and ":wq" to save and close the page. Enter the following command to make the configuration take effect.

source /etc/profile

Go to the bin folder and find jmeter, and check whether the jmeter executable program has executable permissions. If not, you need to execute chmod +x jmeter to grant permissions.

Enter the following command. If the version information of jmeter is printed, the configuration is complete:

jmeter -v

Print the following picture:
Insert image description here

2. Using jmeter on Linux

jmeter on mac has a graphical interface, which is very simple to use, while jmeter on Linux does not have a graphical interface, so you need to rely on the command line to use it. Let’s first learn about jmeter related commands. A complete list of jmeter commands is provided in the following section for reference.

2.1. jmeter command list

short command long command describe
–? Print command line options and exit
-v --version Print version information and exit
-p --propfile <argument> JMeter properties file to use
-q --addprop <argument> Additional JMeter properties files
-t --testfile <argument> JMeter test (.jmx) file to run. "-t last" will load the last used file
-l --logfile <argument> File to log sample
-i --jmeterlogconf <argument> JMeter logging configuration file (log4j2.xml
-j --jmeterlogfile <argument> JMeter running log file (JMeter.log)
-n --nongui Running jmeter in non-GUI mode
-s --server Run JMeter server
-E --proxyScheme <argument> Set proxy scheme for proxy server
-H --proxyHost <argument> Set up proxy server for JMeter to use
-P --proxyPort <argument> Set the JMeter proxy server port to use
-N --nonProxyHosts <argument> Set a list of non-proxy hosts (for example: *.apache.org | localhost)
-u --username <argument> Set the username for the proxy server used by JMeter
-a --password <argument> Set the password for the proxy server used by JMeter
-J --jmeterproperty <argument>=<value> Define other JMeter properties
-G --globalproperty <argument>=<value> Define global properties (sent to the server) such as -Gport=123 or -Gglobal.properties
-D --systemproperty <argument>=<value> Define other system properties
-S --systemPropertyFile <argument> Attached system properties file
-f --forceDeleteResultFile If before starting the test, force delete existing results files and web report folders
-L --loglevel <argument>=<value> [category=]level 例如:jorphan=INFO, jmeter.util=DEBUG or com.example.foo=WARN
-r --runremote Start the remote server (as defined in remote_hosts)
-R --remotestart <argument> Start these remote servers (override remote_hosts)
-d --homedir <argument> Using JMeter home directory
-X --remoteexit Exit the remote server at the end of the test (non-GUI)
-g --reportonly <argument> Generate report dashboard only from test result files
-e --reportatendofloadtests Generate reporting dashboard after load testing
-o --reportoutputfolder <argument> The output folder of the report dashboard. The folder must be empty, otherwise it will fail.

2.2. Commonly used jmeter commands

When performing simple JMeter scenario testing, such as single-pressure non-distributed single-interface pressure testing, you can directly execute the following command:

jmeter -n -t xxx.jmx

In the above command, -n means running in non-gui mode, and -t xxx.jmx means running the xxx.jmx test plan.
In actual testing, additional commands can be used to add functionality. as follows:

jmeter -n -t xxx.jmx -l xxx.jtl -e -o xxx/xxx

Execute the above command. After the execution is completed, the xxx.jtl file will be generated, and a dashboard report will be generated in the xxx/xxx directory. xxx.jtl can be downloaded locally and viewed in gui mode (such as in summary reports, viewing result trees, etc.) as shown below. Select the jtl file, click Browse, and the data will be imported: jmeter supports generating html reports from jtl files through commands
Insert image description here
.

jmeter -g 2h.jtl -e -o report/2hReport

After the command is executed, a 2hReport folder is generated in the report directory. This folder contains the index.html file, which can be opened in the browser.

The index.html file cannot exist apart from other files in the folder. If you only download the index.html file and open it, the web page test report will not be displayed normally.

In stability testing scenarios, the following commands are often used:

nohup jmeter -n -t jmx/tcmi.jmx -l 2h.jtl > 2h_nohup.csv 2>&1 &

Adding nohup in front can keep running in the background during long-term stability tests. Even if the local connection is disconnected from the remote press, the script can continue to be executed on the remote terminal without hanging.

3. Analysis of jmeter’s GUI mode

In the above, a jmx file is used to execute jmeter on the command line. This file is a test plan file, which plays an important role in the entire stress testing process. Generally speaking, it is generated in the graphical mode of jmeter. In other words, I first debugged the script in the jmeter graphical mode of mac, obtained the jmx file, and then uploaded the file to the linux press for execution. Let's take a look at how to use jmeter's graphical mode to output jmx files, or run stress tests directly in jmeter's graphical mode.

3.1. Start the jmeter graphical interface on mac

Directly download the jmeter compressed package on mac and decompress it without configuring environment variables. After decompression, open the command line terminal and execute the following command to start jmeter.

sh /Users/zy/apache-jmeter-5.4.3/bin/jmeter

/Users/zy/apache-jmeter-5.4.3/bin/jmeter is the path to my decompressed jmeter executable file. The executable file is placed in the bin directory under the unzipped folder.
Insert image description here

After successfully executing the above command, the graphical interface can be opened. At this time, the command line prints as follows:
Insert image description here
Don't worry about it. Let's look at the graphical interface of jmeter.
Insert image description here
This interface is a Chinese graphical interface. The default when opening jmeter is English. You can select simplified Chinese through the language selection in "Options" on the top menu bar.
Insert image description here

Personally, I prefer to use English.

Guess you like

Origin blog.csdn.net/u011090984/article/details/128716325