This repository demonstrates the most important default Spring Boot metrics which are enabled through the Spring Boot Actuator module:
- Spring MVC metrics
- Outbound request metrics for
RestTemplate
andWebClient
- JVM metrics
For a full explanation see the accompanying Spring Boot default metrics article at tomgregory.com or YouTube video.
To run this project you'll need:
- JDK 11+
- Docker
Build and run the project using Docker compose with the following command:
./gradlew assemble docker dockerComposeUp
This will startup:
- Spring Boot application at localhost:8080 exposing several APIs
- API 1 is a simple GET API which adds a small random latency
- API 2 is a simple GET API which adds a larger random latency
- API 3 is a GET API that makes a request to another application using
RestTemplate
(see below) - Prometheus metrics for the Prometheus service to scrape (see below)
- nginx application at localhost:8081 to act as the 2nd application to be called using
RestTemplate
. It always returns a 200 response. - Prometheus service at localhost:9090 which is preconfigured to scrape from the Spring Boot application
To avoid having to hit the APIs by hand in order to demonstrate the Prometheus metrics, a Gatling script is included which will hit all the different APIs multiple times over 30 seconds. See BasicSimulation.scala for details of how this is done.
Just run:
./gradlew gatlingRun
Try out these simple queries on Prometheus:
rate(http_server_requests_seconds_count[1m])
rate( http_server_requests_seconds_sum[1m]) / rate(http_server_requests_seconds_count[1m])
http_server_requests_seconds{quantile="0.95"}
rate(http_client_requests_seconds_sum[1m]) / rate(http_client_requests_seconds_count[1m])
sum(jvm_memory_used_bytes{area="heap"})
See more examples in the Spring Boot default metrics article at tomgregory.com
To stop all the applications in this project, just run:
./gradlew dockerComposeDown