I installed prometheus with docker using the official guide on their page. Now I also have node_exporter working on the host. Yet prometheus doesn't seem to scrape metrics of it.
I run prometheus using:
sudo docker run -d -p 9090:9090 -v /home/main/prometheus/config.yml:/etc/prometheus/prometheus.yml prom/prometheus
- job_name: node
static_configs:
- targets: ['localhost:9100']
curl -i localhost:9100
HTTP/1.1 200 OK
Content-Length: 150
Content-Type: text/html; charset=utf-8
<html>
<head><title>Node Exporter</title></head>
<body>
<h1>Node Exporter</h1>
<p><a href="/metrics">Metrics</a></p>
</body>
</html>

apparently, this is fixed using the "-net=host" flag when running on docker:
sudo docker run --net=host -d -p 9090:9090 -v /home/main/prometheus/config.yml:/etc/prometheus/prometheus.yml prom/prometheus
Why are they not telling about this? Prometheus can't access anything outside its container without this flag?
In the documentation, the examples assume that Prometheus and the node exporter are running on the same host. In your case, Prometheus is running on docker, which means that the node exporter is located outside of the container.
You should try to reach your target with the container name, an IP, or with host.docker.internal or similar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With