Jmeter, a performance tool, starts with the SpringBoot project
"This is the 15th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021."
background
Jmeter performance test is usually executed under Linux through the command line. In order to exercise my code and logic ability, I want to know whether Jmeter can be started by springBoot project. I tried to write it at home on weekends. There are still problems to deal with, the following is the corresponding code, in fact, there are online, but the key is to consciously collect knowledge, to use the time can be used to change.
precondition
Jmeter needs to be configured in Linux and Java environment variables need to be configured:
# # editor
vi ~/.bash_profile
# jmeter: The path changes according to your situationJMETER_HOME = / root/tools/apache jmeter - 5.1.1 PATH =$PATH:$HOME/bin:$JMETER_HOME/bin:
export PATH
## Execution takes effect
source ~/.bash_profile
Copy the code
Page design
Running effect
Click upload script, and the dialog box pops up. Click Upload, and the background log shows that the upload is successful.
Click Start and read the startup log.
Click stop.
Schematic illustration:
Access - Call JAVA code - Start shell command - Start Jmeter - get the start log
Reference code
The front-end code
The following reference code:
! DOCTYPEhtml
html lang="en" xmlns:th="http://www.thymeleaf.org"
head
meta charset="utf-8"
meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"
meta name="description" content=""
meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors"
meta name="generator" content="Jekyll v3.8.6"
titleJmeter start/title
link rel="canonical" href="https://v4ing.bootcss.com/docs/4.3/examples/checkout/"
! -- Bootstrap core CSS --
! -- Bootstrap core CSS --
link href="asserts/css/bootstrap.min.css" th:href="@ {/ webjars/bootstrap / 4.3.1 / CSS/bootstrap CSS}" rel="stylesheet"
! -- Favicons --
meta name="theme-color" content="#563d7c"
style
.bd-placeholder-img {
font-size: 1.125 rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5 rem; }}/style
! -- Custom styles for this template --
link href="https://v4.bootcss.com/docs/4.3/examples/checkout/form-validation.css" rel="stylesheet"
/head
body class="bg-light"
div class="container"
div class="py-5 text-center"
img src="https://jmeter.apache.org/images/logo.svg" class="d-block mx-auto mb-4" alt="Apache JMeter"
p class="lead"The Apache JMeter™ application is open source software, a 100% pure Java application designed to
load test functional behavior and measure performance. It was originally designed for testing Web
Applications but has since expanded to other test functions./p
/div
div class="col-md-8 order-md-1"
h4 class="mb-3"Upload script/h4
form
input id="jmeterId" type="file"/
a class="btn btn-lg btn-primary btn-block" value="Upload script" onclick="submitupload()"Upload script/a
/form
form
input id="jmeterParam" type="file"/
a class="btn btn-lg btn-primary btn-block" value="Upload parameters" onclick="submitParm()"Uploading parameter files/a
/form
h4 class="mb-3"run/h4
! -- jmeter -n -t [jmx file] -l [results file] -e -o [Path to web report folder]--
form class="needs-validation" novalidate
div class="row"
div class="col-md-6 mb-3"
label for="jmeterName"Pressure test script/label
input type="text" class="form-control" id="jmeterName" name="jmeterName" placeholder="jmx file"
value="" required
div class="invalid-feedback"
jmx file
/div
/div
div class="col-md-6 mb-3"
label for="numberName"concurrency/label
input type="text" class="form-control" id="numberName" name="num" placeholder="Concurrent number" value=""
required
div class="invalid-feedback"concurrency/div
/