Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.


1 Answers

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

like image 199
Ha. Huynh Avatar answered Nov 25 '25 10:11

Ha. Huynh