Search code examples
amazon-web-servicescurlprometheusprometheus-node-exporter

Can't access node_exporter from public ip address on EC2


I am setting up prometheus/node_exporter on AWS EC2. With the following configuration

[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target

And I can access metrics by using curl with localhost. Something like the following

curl localhost:9100/metrics

I can access the metric via private IP address as well. For example

curl private_ip_address:9100/metrics

But, when I try to access it via public IP address. It's not working, got curl timeout.

curl public_ip_address:9100/metrics

I try accessing from the ipv4:9100 from the server itself and from my local machine. Both got the same issue.

How can I enable to make it accessible from the ipv4 address?


Solution

  • By default, EC2 instances do not allow accessing the port directly.

    You need to create a Custom TCP rule for the port 9100 in the Inbound rules if it does not exist.

    If you have also configured a firewall, you need to allow port 9100 too.

    You can test remote ports are reachable or not (REF: https://stackoverflow.com/a/9463554/664229):

    nc -zvw 5 <ip> <port>