Buona scoperta, ma se provo a puntare a quella porta specifica ricevo un messaggio “connection refused”.
Get "http://discourse_app:9405/metrics": dial tcp 172.20.0.2:9405: connect: connection refused
Ho anche testato con wget dall’interno del container prometheus per essere sicuro.
/prometheus # ping discourse_app
PING discourse_app (172.20.0.2): 56 data bytes
64 bytes from 172.20.0.2: seq=0 ttl=64 time=0.223 ms
64 bytes from 172.20.0.2: seq=1 ttl=64 time=0.270 ms
^C
--- discourse_app ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.223/0.246/0.270 ms
/prometheus # wget discourse_app:9405/metrics
Connecting to discourse_app:9405 (172.20.0.2:9405)
wget: can't connect to remote host (172.20.0.2): Connection refused
Sì, ho testato con wget (il container prometheus è un busybox minimale) ma sono comunque riuscito ad accedere alle metriche.
Quindi, quello che stai dicendo è che dovrei trovare un modo per far sì che il container che esegue prometheus abbia una voce in /etc/hosts che risolva… ti ho perso, scusa ![]()
Quello che ho fatto è aggiungere un altro docker con semplicemente un nginx al suo interno e fornire una configurazione di forward proxy che aggiunge l’header Host alle richieste che riceve. Non espone alcuna porta, quindi può essere accessibile solo dalla rete virtuale interna.
Quindi, come cambiano le cose?
Prometheus Job:
- job_name: discourse_exporter_proxy
scheme: http
static_configs:
- targets:
- 'discourse_forward_proxy:8080'
docker-compose.yaml (solo la parte con il proxy)
version: "3"
services:
# [...]
discourse_forward_proxy:
image: nginx:latest
container_name: discourse_forward_proxy
restart: unless-stopped
volumes:
- ./discourse_forward_proxy/:/etc/nginx/conf.d
networks:
- prometheus-discourse_forward_proxy
- discourse
# [...]
networks:
prometheus-discourse_forward_proxy:
internal: true
discourse:
external: true
Nella directory in cui si trova il tuo docker-compose.yaml, crea ./discourse_forward_proxy/discourse_forward_proxy.conf
server {
listen 8080;
location /metrics {
proxy_set_header Host "YOUR_DOMAIN_HERE.COM";
proxy_pass https://discourse_app/metrics;
}
}
Ecco fatto:
