user9092892
user9092892

Reputation:

prometheus is not able to access metrics from localhost

I have been trying to configure prometheus to show metrics in grafana for my nodejs application. For metrics, I am using prom-client. However, on localhost I get always following error:

Get http://localhost:5000/metrics: dial tcp 127.0.0.1:5000: connect: connection refused

Moreover, if I use a local tunneling service, such as ngrok, it will be able to read the metrics. What am I missing ? I need to add some special config somewhere ?

This is my prometheus.yml file:

global:
    scrape_interval: 5s
    external_labels:
        monitor: 'my-monitor'
scrape_configs:
    - job_name: 'prometheus'
      static_configs:
               - targets: ['localhost:9090']
    - job_name: 'my-app'
      static_configs:
               - targets: ['localhost:5000']

I am running the default prometheus image with docker-compose, same for grafana.

Upvotes: 3

Views: 13509

Answers (1)

Rom
Rom

Reputation: 1838

Because you're using docker-compose, therefore localhost or 127.0.0.1 won't work in the docker container.

You can replace localhost with your machine IP or use ngrok as you did, docker can resolve it to your IP.

Thanks for reading :D

Upvotes: 9

Related Questions