Skip to content

[Java][Metrics] Observability metrics stack with Java (Quarkus and Spring Boot) + Micrometer + Prometheus + Grafana

License

Notifications You must be signed in to change notification settings

helpdeveloper/java-observability-metrics

Repository files navigation

Observability: Monitoring your application from metrics

This repository contains sample Spring Boot and Quarkus application that exposes metrics to Prometheus and Grafana.

The goal of this project was to showcase how to instrumentation your application and collect and monitor application's metrics running inside docker compose.

More detail in this article written in PT-BR: Observabilidade: Monitorando sua aplicação a partir de métricas

Architecture

The project contains the following components:

Tecnologies:

  • Java 17
  • Spring Boot 3
  • Quarkus 2.15
  • Docker Compose
  • Prometheus 2.26
  • Grafana 9.3

Execution

We have two docker-compose files to separate the stack and applications

To facilitate the execution of this example, we created a Makefile script with the following instructions:

  • build: Execute build mvnw clean install on projects
  • install: Build the projects Dockerfile
  • run-stack: Execute only docker-compose-stack.yml
  • run-apps: Execute only docker-compose-apps.yml
  • run-all: Execute all steps above
  • stop-stack: Stop stack
  • stop-apps: Stop apps
  • stop-all: Stop stack and apps

Execute the desired instruction:

$make {desired-instruction}

Prometheus UI

Grafana UI

Test the apps métrics

Spring Boot: http://localhost:8081 Quarkus: http://localhost:8080

Both have a /hello endpoint with a Query Param name which will be metrified. The custom metrics generated are:

  • hello_get_method_timer: Time metric about method duration
  • hello_get_do_process_timer: Time metric about doProcess method duration
  • hello_get_name_length_limit: Count metric increases when the Query Param name exceed the length limit (currently 10)

Call that endpoint:

$curl 'http://localhost:{port}/hello?name={any name}'

Monitoring

We have Grafana as monitoring in conjunction with Prometheus listening to the metrics of the applications, a default dashbord was created that automatically goes up in Grafana; (dashboards location)

  • JVM (Micrometer) Dashboard

  • Application Metrics Dashboard

Contribute

Pull Requests are welcome. For important changes, open an 'issue' first to discuss what you would like to change. Be sure to update tests as appropriate.

Developer

Guilherme Biff Zarelli

Blog/Site - https://helpdev.com.br

LinkedIn - https://linkedin.com/in/gbzarelli/

GitHub - https://github.com/gbzarelli

Medium - https://medium.com/@guilherme.zarelli

Email - gbzarelli@helpdev.com.br

About

[Java][Metrics] Observability metrics stack with Java (Quarkus and Spring Boot) + Micrometer + Prometheus + Grafana

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published