🚀 Deploying Prometheus + Grafana Monitoring Stack on AWS EC2

Monitoring your infrastructure is a must for modern DevOps. In this tutorial, we’ll deploy a Prometheus + Grafana monitoring stack on an AWS EC2 instance running Amazon Linux 2.
By the end, you’ll have:
✅ Prometheus running on port
9090
✅ Grafana running on port
3000
✅ Node Exporter running on port
9100
✅ Dashboards in Grafana connected to Prometheus
📌 Prerequisites
AWS account
EC2 instance (Amazon Linux 2)
Type:
t3.medium
Storage: 20GB SSD
Security Group with Inbound Rules:
SSH → 22
Grafana → 3000
Prometheus → 9090
Node Exporter → 9100
Key pair (
grafana.key.pem
)
🔑 Step 1: Launch EC2 & SSH
Launch an EC2 instance with Amazon Linux 2, t3.medium, 20GB SSD.
Create/download a key pair
grafana.key.pem
.SSH into your instance:
cd ~/Downloads chmod 400 grafana.key.pem ssh -i "grafana.key.pem" ec2-user@
Step 2: Update Packages & Install Git
sudo yum update -y sudo yum install git -y
📜 Step 3: Run Installation Script
Make the script executable and run it:
cd ec2-grafana-prometheus-project git clone https://github.com/lastoyster/observabilitywithprometheus/aws-ec2-nodexport/script.sh
📜sudo chmod +x script.sh sudo ./script.sh
This will install all three at once:
Grafana Enterprise (port
3000
)Prometheus v2.52.0 (port
9090
)Node Exporter v1.8.0 (port
9100
)
🖥️ Step 4: Access Services
Grafana Endpoint→
http://<EC2-Public-IP>:3000
Login:
admin / admin
(set new password)Prometheus →
http://<EC2-Public-IP>:9090
Node Exporter →
http://<EC2-Public-IP>:9100
📊 Step 5: Connect Grafana to Prometheus
Login to Grafana (
admin/admin
).Navigate to:
Configuration → Data Sources→ Add Data Source → Prometheus
Endpoint URL:http://localhost:9090
Step 6: Import Node Exporter Dashboard
Grafana has a large library of pre-built dashboards.
To visualize system metrics, import the Node Exporter Full Dashboard (ID: 1860):
In Grafana, click + → Import Dashboard
Enter ID:
1860
Choose Prometheus as the data source
Import → You’ll see CPU, memory, disk, and network usage
Why Node Exporter ?
Prometheus itself is just a time-series database and scraper — it pulls metrics from defined targets. But your EC2 instance doesn’t expose CPU, memory, or disk usage by default.
That’s where Node Exporter comes in.
It’s a lightweight agent that runs on Linux servers and exports OS-level metrics (CPU load, RAM usage, disk, network, etc.) in a Prometheus-friendly format.
In short:
Prometheus → stores & queries metrics
Node Exporter → collects Linux system metrics
Grafana → visualizes everything
✅ Final Verification
Grafana Dashboards:
http://<EC2-Public-IP>:3000
Prometheus Targets:
http://<EC2-Public-IP>:9090/targets
Node Exporter Metrics:
http://<EC2-Public-IP>:9100/metrics
Adding Nginx and MySQL Exporters to Prometheus + Grafana
So far, our setup collects system-level metrics using Node Exporter. But in real-world AWS deployments, you’ll want visibility into your application stack — like Nginx (reverse proxy/web server) and MySQL (database).
We’ll install:
Nginx Exporter → to monitor web server requests, connections, and response times
MySQL Exporter → to monitor database queries, connections, and slow queries
🌐 Step 1: Install & Configure Nginx + Exporter
1. Install Nginx
On your EC2 instance:
sudo amazon-linux-extras enable nginx1
sudo yum install -y nginx
sudo systemctl enable --now nginx
Check Nginx is running:
http://<EC2-IP>
→ should show the Nginx welcome page.
2. Enable Nginx Stub Status
Prometheus requires Nginx to expose metrics. Add this block inside /etc/nginx/nginx.conf
under server { ... }
:
location /stub_status { stub_status; allow 127.0.0.1; deny all; }
- Restart Nginx Server
🎉 Conclusion
You’ve successfully deployed a Prometheus + Grafana monitoring stack on AWS EC2 (Amazon Linux 2) using a
t3.medium
instance.This setup gives you:
Real-time system monitoring (via Node Exporter)
Centralized dashboards (Grafana)
Flexible alerting (Prometheus rules)
- Click Save & Test → should show ✅ success.
Subscribe to my newsletter
Read articles from Pratiksha kadam directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
