- Create a docker network interface for prometheus,grafana and Java application to talk to each other.
docker network create grafana-prometheus
- Run the prometheus container with prometheus.yaml, I am exposing it the port to be 9095 instead of 9090 as its already occupied on my machine
docker run --name my-prometheus --network grafana-prometheus --network-alias prometheus --mount type=bind,source=C:/work/setup/prometheus/prometheus.yml,destination=/etc/prometheus/prometheus.yml -p 9095:9090 prom/prometheus
PROMETHEUS SCRAPES metrics from application by polling
- Confirm if prometheus runs and shows docker metrics Prometheus local setup
- Run the grafana container to persist data across multiple restarts of docker. You need to create a C:/work/setup/prometheus/grafana directory to persist data on main machine.
docker run --rm --name grafana2 --network grafana-prometheus --network-alias grafana --publish 3000:3000 -v C:/work/setup/prometheus/grafana:/var/lib/grafana --detach grafana/grafana-oss:latest
-
Confirm if Grafana is running Grafana local setup
-
To display Prometheus metrics in Grafana:
- Log into Grafana (default username "admin" and password "admin").
- Go to Configuration > Data sources
- Click Add data source
- Pick Prometheus as the data type
- Set the URL as http://prometheus:9090 and click Save & test down the bottom.
- We use "prometheus" instead of "localhost" because that's the internal network name for our Prometheus container (within the network "grafana-prometheus").
-
Run The spring Boot app
For further reference, please consider the following sections:
- Official Apache Maven documentation
- Spring Boot Maven Plugin Reference Guide
- Create an OCI image
- Spring Boot Actuator
- Prometheus
The following guides illustrate how to use some features concretely: