Prometheus Node Exporter Installation on EC2 Instance - jvcastaneda/DevopsToolingConfig GitHub Wiki

To scrape metrics from an EC2 instance where Prometheus Node Exporter is installed, follow these steps:


1. Verify Node Exporter on EC2 Instance

Ensure Node Exporter is running and exposing metrics on port 9100:

Run this on your EC2 instance:

curl http://localhost:9100/metrics

You should see Prometheus metrics output.


2. Configure Prometheus to Scrape Node Exporter

Update your Prometheus configuration file (prometheus.yml) to include the EC2 instance as a scrape target.

Here is an example prometheus.yml configuration:

global:
  scrape_interval: 15s  # How frequently Prometheus scrapes targets

scrape_configs:
  - job_name: 'node_exporter'  # Job name for node_exporter metrics
    static_configs:
      - targets:
          - <EC2_PUBLIC_IP>:9100  # Replace with the EC2 instance's public IP

3. Update Prometheus Configuration on Your Server

  1. If you are running Prometheus on a separate server, replace <EC2_PUBLIC_IP> with the public IP or private IP of the EC2 instance.

    • If Prometheus and Node Exporter are on the same instance, use localhost:9100.
  2. Restart Prometheus to apply changes:

sudo systemctl restart prometheus

Or, if you are running Prometheus in Docker:

docker restart prometheus

4. Allow Inbound Traffic on Port 9100 (Security Group)

If Prometheus is on a different server, you must allow access to port 9100 on the EC2 instance's security group:

  1. Go to the AWS EC2 Console > Security Groups.
  2. Edit the inbound rules of the EC2 instance:
    • Add a new rule:
      • Type: Custom TCP Rule
      • Port Range: 9100
      • Source: Prometheus server IP (or 0.0.0.0/0 for all, but restrict this for security).

5. Verify Prometheus is Scraping Node Exporter

  1. Go to your Prometheus server UI:

    http://<PROMETHEUS_SERVER_IP>:9090
    
  2. Under Targets (Status > Targets), you should see the Node Exporter job with its status as "UP".

  3. Test the metrics in Prometheus by querying the node_exporter metrics. Example:

    node_cpu_seconds_total
    node_memory_MemAvailable_bytes
    

6. (Optional) Use DNS or Auto-Discovery for Dynamic EC2 Instances

If you have multiple EC2 instances, you can:

  1. Use DNS names instead of IPs (e.g., node-1.example.com:9100).
  2. Use AWS EC2 Service Discovery in Prometheus to dynamically discover instances: Add this snippet to prometheus.yml:
scrape_configs:
  - job_name: 'ec2_node_exporter'
    ec2_sd_configs:
      - region: 'us-west-2'  # Replace with your AWS region
        access_key: '<AWS_ACCESS_KEY>'
        secret_key: '<AWS_SECRET_KEY>'
    relabel_configs:
      - source_labels: [__meta_ec2_tag_Name]
        target_label: instance

Final Check

  1. Visit Prometheus at http://<PROMETHEUS_SERVER_IP>:9090.
  2. Confirm Node Exporter is listed under Targets.
  3. Query relevant metrics like:
    • node_cpu_seconds_total
    • node_filesystem_avail_bytes
    • node_network_receive_bytes_total

Now your Prometheus server will successfully scrape Node Exporter metrics from the EC2 instance! 🚀

Let me know if you need help with advanced configurations like EC2 discovery or Grafana visualization!