This project shows how to set-up Micrometer in a Spring Boot application, using Influx
and Prometheus
.
This springboot app has enabled actuator
to persist metrics in 2 micrometer implementations:
Influx
: Metrics saved in metrics data base and exposed in url http://localhost:8086/.Prometheus
: Metrics exposed in url http://localhost:9090/.
- Download the docker-compose file:
wget https://raw.githubusercontent.com/guedim/spring-projects/master/micrometer/docker-compose.yml
- Next, start SpringBoot service with its dependencies (Influx and Prometheus using docker-compose):
docker-compose up
For getting service metrics run multiple times SpringBoot endpoint :
http://localhost:8080/jobs/github/1
http://localhost:8080/jobs/github/2
http://localhost:8080/jobs/github/3
First, connect to the container:
docker exec -it micrometer_influxdb_1 influx
Into influx container, run the command:
SHOW DATABASES;
Next, connect to metrics
database and list all metrics:
USE metrics;
SHOW MEASUREMENTS;
Finally, run querys for some specific MEASUREMENTS
i.e:
select * from process_cpu_usage;
Validate Prometheus is collecting SpringBoot metrics checking our endpoint my.local.machine
and job prometheus-spring
are running:
http://localhost:9090/targets
Next, check we have Spring metrics in section Highest Cardinality Metric Names
:
http://localhost:9090/status
Finally, query some metrics using next endpoint:
http://localhost:9090/graph
- For build project in local env without docker use next command:
mvn clean package docker:build -DskipTests
- For osx with docker, please run next command:
sudo ifconfig lo0 alias 172.16.222.111