Table of contents
Method 1: Build in Windows or macOS environment
Method 2: Build in Linux environment
Method 3: Install under the docker container
1. Install and run influxdb (select a version below 2.0)
2. Grafana installed and running
【introduction】
In the current fierce market competition, innovation and efficiency have become one of the core elements of enterprise development. In this context, how to ensure the stability, reliability and efficiency of products and services is particularly important.
In the software development process, performance testing is an indispensable link, which can effectively evaluate the performance indicators of a system, application or software. However, how to improve performance testing efficiency and convert test results into valuable information is a more important issue.
Therefore, this article provides an optimized integration solution based on JMeter, Grafana and Influxdb, intelligently integrating the three tools, and through real-time monitoring and data analysis, to help the team better discover and solve performance problems, and improve products and services for the enterprise quality and lay a solid foundation. Whether you are a team leader, test engineer, operation and maintenance engineer or other technical personnel, you can easily build an intelligent performance test monitoring platform through the solution in this article, so as to gain a greater advantage in the fierce market competition.
【Background】
When using jmeter for performance testing, the way to view the results that comes with the tool is often not intuitive and clear enough, so we need to build a visual monitoring platform to complete the result monitoring. Here we use three methods of JMeter+Grafana+Influxdb to complete the platform construction
【Principle of Implementation】
Store the jmeter results through the influxdb database, and then collect the influxdb database data through grafana to complete the monitoring platform display
【Platform Construction】
Method 1: Build in Windows or macOS environment
1.InfluxDB installation
First go to the influxDB official website to download the installation package (choose a version below 2.0)
https://portal.influxdata.com/downloads/
Windows can be downloaded directly using the link below
https://dl.influxdata.com/influxdb/releases/influxdb-1.7.9_windows_amd64.zip
After the download is complete, decompress it. Take Windows as an example:
Enter the folder to see the following directories
Click influxd.exe to start the database, the startup is successful as shown in the figure below
Click influx.exe to enter the influxdb client, and create a database named "jmeter" after entering
2. grafana installation
First enter the grafana official website to download the installation package
https://grafana.com/grafana/download
Select the corresponding system and download it, taking Windows as an example:
After the decompression is complete, enter the bin directory and click grafana-server.exe
to start the grafana program
After the startup is complete, open the browser and enter http://localhost:3000
the grafana login page
The default user name and password are both admin, click to add database after entering the home page
Select the influxdb database and fill in the following information
Click sava&test, it will display data source is working, indicating that the database connection is successful
Import the downloaded dashboard
You can also go to the grafana official website to find templates, and enter the Downlosds number of the required template in the import template.
https://grafana.com/grafana/dashboards
Finally as shown
3.jmeter configuration
1. In jmeter, add "Listener -> Backend Listener"
Configure the backend listener, the purpose is to store the results of jmeter into the influxdb database
Method 2: Build in Linux environment
1.Influxdb installation
Install influxdb directly using the command
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.4_linux_amd64.tar.gz
Decompress the influxdb compressed package
tar -zxvf influxdb-1.8.4_linux_amd64.tar.gz
Add environment variables
cd influxdb-1.8.4-1/usr/bin
sudo cp {influx,influxd} /usr/local/bin/
start influxdb
influxd
Start the influxdb client and create the jmeter database
influx
create database jmeter
2. grafana installation
Install directly with the command
wget https://dl.grafana.com/oss/release/grafana-7.5.2.linux-amd64.tar.gz
Unzip the installation package
tar -zxvf grafana-7.5.2.linux-amd64.tar.gz
start grafana
cd grafana-7.5.2/bin
./grafana-server
Visit the grafana web page, and the rest of the operations are the same as method 1
http://ip:3000
3.jdk+jmeter installation
Before installing jmeter, you need to install jdk first, download jdk (you can use the following address to download, or you can go to the official website to download, the official website needs to log in to oracle) https://www.jdkdownload.com/
, I choose jdk-8u181-linux-x64.tar.gz
the version to download
decompress jdk
tar -zxvf jdk-8u181-linux-x64.tar.gz
Configure environment variables, modify the configuration file vi /etc/profile
, and add the following at the end of the text
JAVA_HOME=/usr/local/java/jdk1.8.0_181
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
make the environment variable take effect
source /etc/profile
Verify that the jdk configuration is successful
java -version
Install jmeter directly using the command
wget https://mirrors.bfsu.edu.cn/apache//jmeter/binaries/apache-jmeter-5.4.3.tgz
Unzip jmeter
tar -zxf apache-jmeter-5.4.3.tgz
Configure the jmeter environment variable, vi /etc/profile
, add the following at the end of the text
export JMETER_HOME=/usr/local/apache-jmeter-5.4.3
export CLASSPATH=$JMETER_HOME/lib/ext/ApacheJMeter_core.jar:$JMETER_HOME/lib/jorphan.jar:$CLASSPATH
export PATH=$JMETER_HOME/bin:$PATH
make the environment variable take effect
source /etc/profile
Verify jmeter configuration is successful
jmeter --version
Upload the jmeter script to the current folder, execute the following command to start jmeter
jmeter -n -t ***.jmx -l test.jtl
参数说明:
-n 非 GUI 模式 -> 在非 GUI 模式下运行 JMeter
-t 测试文件 -> 要运行的 JMeter 测试脚本文件
-l 日志文件 -> 记录结果的文件
Method 3: Install under the docker container
1. Install and run influxdb (select a version below 2.0)
docker run -itd --name influxdb -p 8086:8086 influxdb:1.8.3
into the container
docker exec -it influxdb /bin/bash
create database
influx
create database jmeter
show databases
2. Grafana installed and running
docker run -itd --name grafana -p 3000:3000 grafana/grafana
into the container
docker exec -it grafana /bin/bash
Visit the grafana webpage, and the rest of the operations are the same as method 1 (note that the connection to influxdb in the container uses the container ip)
http://ip:3000
3.jmeter installation
First you need to download jmeter
wget https://mirrors.bfsu.edu.cn/apache//jmeter/binaries/apache-jmeter-5.4.3.tgz
We use dockerfile to install, the content is as follows
FROM java:8
ENV http_proxy ""
ENV https_proxy ""
RUN mkdir /jmeterdocker
RUN mkdir -p /jmeterdocker/test
RUN mkdir -p /jmeterdocker/test/input/jmx
RUN mkdir -p /jmeterdocker/test/input/testdata
RUN mkdir -p /jmeterdocker/test/report/html
RUN mkdir -p /jmeterdocker/test/report/jtl
RUN mkdir -p /jmeterdocker/test/report/outputdata
RUN chmod -R 777 /jmeterdocker
ENV JMETER_VERSION=5.4.3
ENV JMETER_HOME=/jmeterdocker/apache-jmeter-${JMETER_VERSION}
ENV JMETER_PATH=${JMETER_HOME}/bin:${PATH}
ENV PATH=${JMETER_HOME}/bin:${PATH}
COPY apache-jmeter-${JMETER_VERSION}.tgz /jmeterdocker
RUN cd /jmeterdocker \
&& tar xvf apache-jmeter-${JMETER_VERSION}.tgz \
&& rm apache-jmeter-${JMETER_VERSION}.tgz
Execute commands under the dockerfile file path
docker build -t jmeter .
Create jmeter container
docker run -itd --name=jmeter -v /tmp/jmeterspace/test/input/jmx:/jmeterdocker/test/input/jmx \
-v /tmp/jmeterspace/test/input/testdata:/jmeterdocker/test/input/testdata \
-v /tmp/jmeterspace/test/report/html:/jmeterdocker/test/report/html \
-v /tmp/jmeterspace/test/report/jtl:/jmeterdocker/test/report/jtl \
-v /tmp/jmeterspace/test/report/outputputdata:/jmeterdocker/test/report/outputdata \
-p 1099:1099 \
jmeter
Put the jmeter script under /tmp/jmeterspace/test/input/jmx
the path outside the container
Enter the container and execute the following command
docker exec -it jmeter /bin/bash
cd /jmeterdocker/test/input/jmx
jmeter -n -t ***.jmx -l test.jtl
参数说明:
-n 非 GUI 模式 -> 在非 GUI 模式下运行 JMeter
-t 测试文件 -> 要运行的 JMeter 测试脚本文件
-l 日志文件 -> 记录结果的文件
The running result is shown in the figure
【summary】
The above three methods can complete the JMeter+Grafana+Influxdb platform construction, here you can choose the corresponding method to install according to your needs
All these methods need to be practiced by us to have a deep feeling and understanding, but the most fundamental method is to maintain our enthusiasm for this industry and the pursuit of best practices. This is how we can constantly break through ourselves and climb the peak An inexhaustible source of motivation!
This post ends here, and finally, I hope that friends who read this post can gain something.
[Message: Get the data, take it away for free]
It's all here, remember to support Sanlian .