Description • Tech Stack • Approaches • Usage • Inspiration
This Spring Boot app aims to show how spring-boot-actuator work together with prometheus and grafana to help you gain metrics.
I used a premade grafana dashboard template from here
- Spring Boot Parent 3.0.6
- Micrometer Prometheus 1.10.6
- Docker
- Github Actions
- docker-file-maven-plugin 1.4.10
There is a clean separation between dependencies and application resources in a Spring Boot fat jar file, and we can use that fact to improve performance. The key is to create layers in the container filesystem. The layers are cached both at build time and at runtime (in most runtimes) so we want the most frequently changing resources, usually the class and static resources in the application itself, to be layered after the more slowly changing resources.
Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its inception in 2012, many companies and organizations have adopted Prometheus, and the project has a very active developer and account community.
The default dashboard for Spring Boot dashboard template can be found here.
Maven plugin for running basic docker-compose commands with Maven. In case of this app, integration tests needed postgres db running via this plugin.
-
./mvnw clean install
for creating the docker image of the app and running tests -
fire up prometheus, grafana and the app itself
docker-compose -f docker/monitoring.yml -f docker/app.yml up --build
-
visit
localhost:8080/api/hello
-
visit
localhost:3000
-
grafana default login credentials is
admin-admin
and skip the password change -
visit provisioned Spring-boot dashboard and fathom micrometer metrics of the app
Note: docker settings (host.docker.internal) works for MacOS, but on Windows it won't. In theory, 'host' should be used on Windows, but I don't have a chance to try it out.