Monitoring AWS EC2 Instances with Prometheus and Grafana using Node Exporter

Zain Hafeez
DevOps.dev
Published in
3 min readJan 24, 2024

--

Prometheus X Grafana

Monitoring your AWS EC2 instances is a crucial aspect of maintaining a healthy and performant infrastructure. In this guide, I will walk you through the process of setting up Prometheus and Grafana to monitor an AWS EC2 instance running Ubuntu using Node Exporter. Additionally, we’ll explore how to import a pre-configured Node Exporter dashboard from the Grafana Marketplace for a seamless monitoring experience.

Prerequisites

Before we begin, make sure you have the following:

  • An AWS EC2 instance running Ubuntu with your application.
  • SSH access to your EC2 instance.
  • Docker installed on your EC2 instance.

What is Prometheus?

Prometheus is an open-source monitoring and alerting toolkit designed for reliability and scalability. It is particularly well-suited for dynamic cloud environments and provides a flexible query language, efficient storage, and robust alerting capabilities.

What is Grafana?

Grafana is a leading open-source platform for monitoring and observability. It allows you to create, explore, and share dashboards, enabling you to visualize and analyze data from various sources. Grafana is highly extensible and supports integration with numerous data sources, making it a popular choice for creating comprehensive monitoring solutions.

Step 1: Install Node Exporter on your Ubuntu-based EC2 instance

Node Exporter is a Prometheus exporter that collects system-level metrics from your machine. To install Node Exporter, SSH into your Ubuntu-based EC2 instance and run the following commands:

wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz
tar -xvzf node_exporter-1.2.2.linux-amd64.tar.gz
cd node_exporter-1.2.2.linux-amd64
./node_exporter

Step 2: Configure Prometheus to scrape Node Exporter metrics

Prometheus needs to be configured to scrape metrics from Node Exporter. Create a prometheus.yml file with the following content:

global:
scrape_interval: 15s

scrape_configs:
- job_name: 'node-exporter'
static_configs:
- targets: ['localhost:9100']

Run Prometheus with Docker:

docker run -p 9090:9090 -v /path/to/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

This will make Prometheus accessible at http://localhost:9090.

Step 3: Install and Configure Grafana

Install Grafana with Docker:

docker run -p 3000:3000 grafana/grafana

Access Grafana at http://localhost:3000 and log in with the default credentials (admin/admin).

Add Prometheus as a data source:

  1. Click on the gear icon (⚙️) in the left sidebar.
  2. Choose “Data Sources” and click on “Add your first data source.”
  3. Select Prometheus and set the URL to http://localhost:9090.

Step 4: Import a Node Exporter Dashboard from Grafana Marketplace

  1. Visit the Grafana Dashboard Marketplace and search for “Node Exporter Full” or navigate to the appropriate section.
  2. Choose a Node Exporter dashboard that aligns with your monitoring requirements. Each dashboard has a unique identifier (UID) associated with it.
  3. Copy the UID and open your Grafana instance.
  4. Go to the “+” icon in the left sidebar, select “Import,” and paste the UID into the “Grafana.com Dashboard” field.
  5. Click “Load,” select the Prometheus data source, and click “Import” to add the dashboard to your Grafana instance.
  6. Explore the imported dashboard, customize panels, add or remove visualizations as needed.

You can generate some alerts as well based on specfic conditions.

Grafana Dashboard using Node-Exporter Full

Alternative: AWS CloudWatch

While Prometheus and Grafana provide powerful monitoring capabilities, AWS users may also consider leveraging AWS CloudWatch. CloudWatch is a fully-managed monitoring service that offers comprehensive insights into AWS resources. You can configure CloudWatch Alarms, set up dashboards, and collect custom metrics, providing an integrated solution for AWS-centric monitoring.

By following these steps, you’ve successfully set up Prometheus and Grafana to monitor your AWS EC2 instance running Ubuntu using Node Exporter. Importing a pre-configured dashboard from the Grafana Marketplace streamlines the monitoring process, allowing you to quickly gain insights into the performance and health of your infrastructure.

Feel free to explore additional Prometheus exporters and Grafana features to enhance your monitoring capabilities further. Happy monitoring!

--

--