This is a simple Spring Boot application created to demonstrate the usage of Micrometer, Prometheus and Grafana.
Key dependencies:
micrometer-registry-prometheuswhich gives us API for metricsspring-boot-starter-actuatorwhich exposes/actuator/prometheusendpoint
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#actuator.metrics
Go to ./docker/prometheus directory and edit prometheus.yml file.
Update scrape_configs[].static_configs[].targets list under books_app job
with your IP address.
On macOS you can use ifconfig | grep "inet " | grep -v 127.0.0.1 command.
After that in ./docker directory run docker-compose start to start Prometheus and Grafana running in Docker.
- Prometheus http://localhost:9090
- Configured job's targets http://localhost:9090/targets
In Prometheus you can see the configured targets, browse metrics and run some queries.
Login credentials are admin/admin. After log in you can either set a new password or skip such step.
You can browse available dashboards under this address: https://grafana.com/grafana/dashboards
JVM (Micrometer) dashboards: https://grafana.com/grafana/dashboards/4701-jvm-micrometer/
You can use hey program to send requests to the service.
https://github.com/rakyll/hey
hey -c 10 -n 50 "http://localhost:8080/api/test"
hey -c 10 -n 20 "http://localhost:8080/api/books"
hey -c 2 -n 15 "http://localhost:8080/api/books?title=Clean%20code"
hey -c 10 -n 50 "http://localhost:8080/api/books?title=Fundamental%20Algorithms"
hey -c 10 -n 50 "http://localhost:8080/api/books?title=Domain%20Driven%20Design"Custom metrics:
books_service_books_in_store_count- gauge - a current number of books in storebooks_service_books_search_by_title- timer showing how long does it take to search for booksbooks_service_api_books_get_count- counter - a number of requests toGET /api/booksendpoint
- avg response time for statuses other than 5..:
sum(rate(http_server_requests_seconds_sum{status!~"5.."}[60s])) / sum(rate(http_server_requests_seconds_count{status!~"5.."}[60s])), labelavg - the longest response time for statues other than 5..:
max(http_server_requests_seconds_max{status!~"5.."}), labelmax - 0.95 quantile
histogram_quantile(0.95, sum by(le) (rate(http_server_requests_seconds_bucket[1m]))), labelp95
rate(books_service_books_search_by_title_seconds_sum[1m]) / rate(books_service_books_search_by_title_seconds_count[1m])- label
{{title}}
rate(http_server_requests_seconds_count[60s])- label
{{uri}}
books_service_books_in_store_count
books_service_api_books_get_count_total, label{{title}}
books_service_api_books_get_count_total{matching_books="0"}, label{{title}}