1

I am running a Docker bundle with these images on my server

 - SpringBoot app : PORT 18081
 - Granafa        : PORT 3001
 - PostgreSQL     : PORT 5432
 - Prometheus     : PORT 9090

and I would like to set up Prometheus to scrape from Springboot with this prometheus.yml configuration:

#My global config
global:
        scrape_interval: 15s
        evaluation_interval: 15s

alerting:
        alertmanagers:
                - static_configs:
                        - targets:
                                # - alertmanager:9093
rule_files:
        # - "first_rules.yml"
        # - "second_rules.yml"

scrape_configs:
        - job_name: prometheus
          static_configs:
                  - targets: ['localhost:9090']

        - job_name: spring-actuator
          scrape_interval: 5s
          scrape_timeout: 5s
          metrics_path: /actuator/prometheus
          scheme: http
          static_configs:
                  - targets: ['172.30.0.9:18081']

where 172.30.0.9 is the docker internal IP for my SpringBoot application obtained with this command:

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container-id>

I checked the Prometheus Dashboard on ip:9090 and I was able to observe that the prometheus job is succesfully scrapped, but not the endpoint from the Spring application.

However, if I perform a curl on the VM machine curl http://172.30.0.9:18081/actuator/prometheus, I succesfully returns all the prometheus metrics.

I have tried to set as target:

  • localhost:18081
  • external_ip:18081
  • container-name:18081
  • host.docker.internal:18081

but Prometheus is still not accessing the endpoint as expected.

Did I miss anything to configure?

  • 1
    did you try using `service-name:18081`? Do you call your server "VM" or the Prometheus container? You shouldn't be able to access it using `curl http://172.30.0.9:18081/actuator/prometheus` from the host machine usually. – Calipee Nov 27 '22 at 21:01

1 Answers1

0

I see some things you may remove since they are redundant, you can try and use the following for scrape_configs (prometheus self-scrape is not necessary as well as some settings - since you defined global):

scrape_configs:
        - job_name: 'spring-actuator'
          metrics_path: '/actuator/prometheus'
          static_configs:
                  - targets: ['172.30.0.9:18081']

There might be some layout issue.

kenneth
  • 478
  • 4
  • 11