简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM