Reputation: 1681
I have a Spring Boot application that is running on 9000 port locally (not in container). The application has configured actuator with Prometheus micrometer and the whole stats is available by URL localhost:9000/actuator/prometheus.
I run Prometheus in Docker container using the following command:
docker run --name spring_boot_prometheus -p 9090:9090 -p 9000:9000 -v /Users/xyz/docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
prometheus.yml
global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_configs:
- job_name: 'users-app'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['localhost:9000']
The command docker ps
returns the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1568ec9e8353 prom/prometheus "/bin/prometheus --c…" 10 seconds ago Up 9 seconds 0.0.0.0:9000->9000/tcp, 0.0.0.0:9090->9090/tcp spring_boot_prometheus
The UI says that prometheus can't connect to spring boot endpoint but it's available. If I click on endpoint it redirects me to 1568ec9e8353:9000
instead of localhost:9000
How can I fix the problem?
Appreciate for your help!
Upvotes: 8
Views: 3423
Reputation: 5361
In prometheus.yml, instead of localhost:9000
put the specific name of the container: spring_boot_prometheus:9000
.
Docker best practice is to use container names instead of container IP addresses.
Upvotes: 3
Reputation: 648
For the prometheus docker container 'localhost' means local. So prometheus tries to connect within the container to port 9000. This will not work.
Also, within the prometheus container does not run a service on port 9000 as far as I can know from your post.
If both apps are in a docker container:
The target container has it's own IP address within your docker installation. Typically 172.17.y.z.
A simple docker network is necessary and after that you run both you containers with that:
$ docker network create mynet
$ docker run --name foo --net mynet img
$ docker run --name bar --net mynet img
Found here: forums.docker.com
If you have the service (9000) running on your machine without docker:
This is not a standard use case
Read here how to set this up.
You have to obtain the IP address of your physical computer. For example 192.168.0.10. This is then the target for prometheus.
Upvotes: 2