From 87c22e5be4d63cfcd6898bf4943c28ce1337803d Mon Sep 17 00:00:00 2001 From: Muhammad Asif Date: Sat, 4 Feb 2023 21:25:23 +0500 Subject: [PATCH] BAEL-5990 is implemented to generate JMeter dashboard reports (#13345) * BAEL-5990 is implemented to generate JMeter dashboard reports * BAEL-5990 made a fix to use Random nextInt() method with single arg * BAEL-5990 updated code to use Arrays.asList rather than List.of * BAEL-5990 Replaced tabs with space * BAEL-5990 Removed unnecessary exception in the method declaration * BAEL-5990 Updated class name --- jmeter/pom.xml | 86 ++++++++++++ .../dashboard/DashboardApplication.java | 15 +++ .../dashboard/controllers/Dashboard.java | 42 ++++++ .../com/baeldung/dashboard/models/Quotes.java | 13 ++ .../resources/dashboard/ReportsDashboard.csv | 16 +++ .../resources/dashboard/ReportsDashboard.jmx | 127 ++++++++++++++++++ jmeter/src/main/resources/static/index.html | 15 +++ .../main/resources/templates/greeting.html | 10 ++ .../src/main/resources/templates/quote.html | 11 ++ jmeter/src/main/resources/templates/time.html | 10 ++ 10 files changed, 345 insertions(+) create mode 100644 jmeter/src/main/java/com/baeldung/dashboard/DashboardApplication.java create mode 100644 jmeter/src/main/java/com/baeldung/dashboard/controllers/Dashboard.java create mode 100644 jmeter/src/main/java/com/baeldung/dashboard/models/Quotes.java create mode 100644 jmeter/src/main/resources/dashboard/ReportsDashboard.csv create mode 100644 jmeter/src/main/resources/dashboard/ReportsDashboard.jmx create mode 100644 jmeter/src/main/resources/static/index.html create mode 100644 jmeter/src/main/resources/templates/greeting.html create mode 100644 jmeter/src/main/resources/templates/quote.html create mode 100644 jmeter/src/main/resources/templates/time.html diff --git a/jmeter/pom.xml b/jmeter/pom.xml index b2e4197dfc..c4b15405ec 100644 --- a/jmeter/pom.xml +++ b/jmeter/pom.xml @@ -68,5 +68,91 @@ 2.6.0 + + + + dashboard + + + env + dash + + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-web + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + launch-web-app + + start + + + com.baeldung.dashboard.DashboardApplication + + + + + + com.lazerycode.jmeter + jmeter-maven-plugin + 3.7.0 + + + + configuration + + configure + + + + + jmeter-tests + + jmeter + results + + + + + ${project.basedir}/src/main/resources/dashboard + ${project.basedir}/src/main/resources/dashboard + true + true + false + + + + org.springframework.boot + spring-boot-maven-plugin + + + stop-web-app + + stop + + + + + + + + + 5.5 + + + \ No newline at end of file diff --git a/jmeter/src/main/java/com/baeldung/dashboard/DashboardApplication.java b/jmeter/src/main/java/com/baeldung/dashboard/DashboardApplication.java new file mode 100644 index 0000000000..a531b97be1 --- /dev/null +++ b/jmeter/src/main/java/com/baeldung/dashboard/DashboardApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.dashboard; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; +import org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration; +import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; + +@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, MongoAutoConfiguration.class, MongoRepositoriesAutoConfiguration.class, MongoDataAutoConfiguration.class }) +public class DashboardApplication { + public static void main(String[] args) throws Exception { + SpringApplication.run(DashboardApplication.class, args); + } +} diff --git a/jmeter/src/main/java/com/baeldung/dashboard/controllers/Dashboard.java b/jmeter/src/main/java/com/baeldung/dashboard/controllers/Dashboard.java new file mode 100644 index 0000000000..8c749b21d8 --- /dev/null +++ b/jmeter/src/main/java/com/baeldung/dashboard/controllers/Dashboard.java @@ -0,0 +1,42 @@ +package com.baeldung.dashboard.controllers; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Random; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; + +import com.baeldung.dashboard.models.Quotes; + +@Controller +public class Dashboard { + + @GetMapping("/greeting") + public String getGreeting(Model model) { + model.addAttribute("host", System.getProperty("os.name")); + return "greeting"; + } + + @GetMapping("/quote") + public String getQuote(Model model) throws InterruptedException { + Random r = new Random(); + int day = r.nextInt(7); + String quote = Quotes.list.get(day); + + int wait = r.nextInt(6); + Thread.currentThread().sleep(wait); + model.addAttribute("quote", quote); + + return "quote"; + } + + @GetMapping("/time") + public String getTime(Model model) { + DateTimeFormatter fmt = DateTimeFormatter.ofPattern("hh:mm:ss a"); + LocalDateTime now = LocalDateTime.now(); + model.addAttribute("time", fmt.format(now)); + return "time"; + } +} diff --git a/jmeter/src/main/java/com/baeldung/dashboard/models/Quotes.java b/jmeter/src/main/java/com/baeldung/dashboard/models/Quotes.java new file mode 100644 index 0000000000..7c8e6a732d --- /dev/null +++ b/jmeter/src/main/java/com/baeldung/dashboard/models/Quotes.java @@ -0,0 +1,13 @@ +package com.baeldung.dashboard.models; + +import java.util.Arrays; +import java.util.List; + +public class Quotes { + public static final List list = Arrays.asList("The greatest glory in living lies not in never falling, but in rising every time we fall. -Nelson Mandela\r\n", + "The way to get started is to quit talking and begin doing. -Walt Disney\r\n", + "Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma – which is living with the results of other people's thinking. -Steve Jobs\r\n", + "If life were predictable it would cease to be life, and be without flavor. -Eleanor Roosevelt\r\n", + "If you look at what you have in life, you'll always have more. If you look at what you don't have in life, you'll never have enough. -Oprah Winfrey\r\n", + "If you set your goals ridiculously high and it's a failure, you will fail above everyone else's success. -James Cameron\r\n", "Life is what happens when you're busy making other plans. -John Lennon"); +} diff --git a/jmeter/src/main/resources/dashboard/ReportsDashboard.csv b/jmeter/src/main/resources/dashboard/ReportsDashboard.csv new file mode 100644 index 0000000000..046666ca2b --- /dev/null +++ b/jmeter/src/main/resources/dashboard/ReportsDashboard.csv @@ -0,0 +1,16 @@ +timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect +1674622105952,714,HTTP Request (/greeting),200,,Thread Group 1-4,text,true,,430,126,5,5,http://localhost:8080/greeting,705,0,7 +1674622105450,1216,HTTP Request (/greeting),200,,Thread Group 1-1,text,true,,430,126,5,5,http://localhost:8080/greeting,1207,0,54 +1674622105468,1198,HTTP Request (/greeting),200,,Thread Group 1-2,text,true,,430,126,5,5,http://localhost:8080/greeting,1189,0,36 +1674622106064,602,HTTP Request (/greeting),200,,Thread Group 1-5,text,true,,430,126,5,5,http://localhost:8080/greeting,593,0,2 +1674622105800,866,HTTP Request (/greeting),200,,Thread Group 1-3,text,true,,430,126,5,5,http://localhost:8080/greeting,857,0,1 +1674622106669,13,HTTP Request (/quote),200,,Thread Group 1-4,text,true,,515,123,5,5,http://localhost:8080/quote,12,0,0 +1674622106669,16,HTTP Request (/quote),200,,Thread Group 1-2,text,true,,548,123,5,5,http://localhost:8080/quote,16,0,0 +1674622106671,18,HTTP Request (/quote),200,,Thread Group 1-1,text,true,,629,123,5,5,http://localhost:8080/quote,18,0,0 +1674622106669,24,HTTP Request (/quote),200,,Thread Group 1-5,text,true,,602,123,5,5,http://localhost:8080/quote,24,0,0 +1674622106669,29,HTTP Request (/quote),200,,Thread Group 1-3,text,true,,515,123,5,5,http://localhost:8080/quote,29,0,0 +1674622106690,18,HTTP Request (/time),200,,Thread Group 1-1,text,true,,432,122,5,5,http://localhost:8080/time,18,0,0 +1674622106699,9,HTTP Request (/time),200,,Thread Group 1-3,text,true,,432,122,5,5,http://localhost:8080/time,9,0,0 +1674622106683,26,HTTP Request (/time),200,,Thread Group 1-4,text,true,,432,122,5,5,http://localhost:8080/time,25,0,0 +1674622106688,25,HTTP Request (/time),200,,Thread Group 1-2,text,true,,432,122,2,2,http://localhost:8080/time,25,0,0 +1674622106695,18,HTTP Request (/time),200,,Thread Group 1-5,text,true,,432,122,2,2,http://localhost:8080/time,17,0,0 diff --git a/jmeter/src/main/resources/dashboard/ReportsDashboard.jmx b/jmeter/src/main/resources/dashboard/ReportsDashboard.jmx new file mode 100644 index 0000000000..081920c671 --- /dev/null +++ b/jmeter/src/main/resources/dashboard/ReportsDashboard.jmx @@ -0,0 +1,127 @@ + + + + + + false + true + false + + + + + + + + Test Greetings Page + continue + + false + 1 + + 5 + 1 + false + + + true + + + + + + + localhost + 8080 + + + /greeting + GET + true + false + true + false + + + + + + + + + + localhost + 8080 + + + /quote + GET + true + false + true + false + + + + + + + + + + localhost + 8080 + + + /time + GET + true + false + true + false + + + + + + + false + + saveConfig + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + true + false + false + false + true + 0 + true + true + true + true + true + true + + + dashapp + + + + + + diff --git a/jmeter/src/main/resources/static/index.html b/jmeter/src/main/resources/static/index.html new file mode 100644 index 0000000000..fe2e1bf095 --- /dev/null +++ b/jmeter/src/main/resources/static/index.html @@ -0,0 +1,15 @@ + + + + + Jmeter Dashboard Test APP + + + + +

Get your Quote here

+

Get your Time here

+

Get your greeting here

+ + + \ No newline at end of file diff --git a/jmeter/src/main/resources/templates/greeting.html b/jmeter/src/main/resources/templates/greeting.html new file mode 100644 index 0000000000..3b023db6b1 --- /dev/null +++ b/jmeter/src/main/resources/templates/greeting.html @@ -0,0 +1,10 @@ + + + + Jmeter Dashboard Test APP + + + +

+ + \ No newline at end of file diff --git a/jmeter/src/main/resources/templates/quote.html b/jmeter/src/main/resources/templates/quote.html new file mode 100644 index 0000000000..8d943c2a3d --- /dev/null +++ b/jmeter/src/main/resources/templates/quote.html @@ -0,0 +1,11 @@ + + + + Jmeter Dashboard Test APP + + + +

+

+ + \ No newline at end of file diff --git a/jmeter/src/main/resources/templates/time.html b/jmeter/src/main/resources/templates/time.html new file mode 100644 index 0000000000..d068bbe050 --- /dev/null +++ b/jmeter/src/main/resources/templates/time.html @@ -0,0 +1,10 @@ + + + + Jmeter Dashboard Test APP + + + +

+ + \ No newline at end of file