π Prometheus + Node Exporter on Ubuntu (AWS EC2)
1οΈβ£ Architecture Overview (What we are building)
EC2 #1 β TARGET (Ubuntu)
- Purpose: expose system metrics
- Tool: Node Exporter
- Port: 9100
EC2 #2 β MONITOR (Ubuntu)
- Purpose: collect and display metrics
- Tool: Prometheus
- Port: 9090
Browser
β
Prometheus (Ubuntu, :9090)
β scrape
Node Exporter (Ubuntu, :9100)
2οΈβ£ AWS SECURITY GROUP SETUP (LAB MODE)
β οΈ This is NOT secure for production
β Used only for training & demos
2.1 Create Security Group (Same steps for both EC2s)
AWS Console β EC2 β Security Groups β Create security group
Inbound Rules
| Type | Protocol | Port | Source |
|---|---|---|---|
| All traffic | All | All | 0.0.0.0/0 |
Outbound Rules
- Keep default: All traffic β 0.0.0.0/0
Attach this SG to:
- Monitor EC2
- Target EC2
3οΈβ£ TARGET EC2 (Ubuntu) β Install Node Exporter
3.2 Download Node Exporter
cd /tmp
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
3.3 Extract & install
tar -xvf node_exporter-1.7.0.linux-amd64.tar.gz
cd node_exporter-1.7.0.linux-amd64
sudo mv node_exporter /usr/local/bin/
3.4 Start Node Exporter (foreground demo)
node_exporter
You should see:
Listening on :9100
3.5 Verify Node Exporter
ss -tulnp | grep 9100
Test metrics:
curl http://localhost:9100/metrics | head
β Node Exporter is ready
4οΈβ£ MONITOR EC2 (Ubuntu) β Install Prometheus
4.1 Connect to MONITOR EC2
ssh ubuntu@<MONITOR_PUBLIC_IP>
4.2 Download Prometheus
cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-2.48.1.linux-amd64.tar.gz
4.3 Extract files
tar -xvf prometheus-2.48.1.linux-amd64.tar.gz
cd prometheus-2.48.1.linux-amd64
4.4 Create directories
sudo mkdir -p /etc/prometheus
sudo mkdir -p /var/lib/prometheus
4.5 Install binaries
sudo mv prometheus promtool /usr/local/bin/
prometheus --version
4.6 Move config files
sudo mv prometheus.yml /etc/prometheus/
sudo mv consoles console_libraries /etc/prometheus/
Verify:
ls /etc/prometheus
Expected:
prometheus.yml
consoles
console_libraries
5οΈβ£ Configure Prometheus (Ubuntu)
5.1 Edit config
sudo nano /etc/prometheus/prometheus.yml
5.2 Replace EVERYTHING with this
(Change <TARGET_PUBLIC_IP>)
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets: []
rule_files: []
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "node"
static_configs:
- targets: ["<TARGET_PUBLIC_IP>:9100"]
Save:
CTRL + O- Enter
CTRL + X
5.3 Validate config (VERY IMPORTANT)
promtool check config /etc/prometheus/prometheus.yml
Expected:
SUCCESS
6οΈβ£ Start Prometheus (Ubuntu)
prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus
Look for:
Server is ready to receive web requests.
7οΈβ£ Access Prometheus UI
Open browser:
http://<MONITOR_PUBLIC_IP>:9090
Navigate to:
Status β Targets
β Expected result
prometheus UP
node UP
This confirms:
- Networking works
- Security group works
- Metrics are being scraped
8οΈβ£ Live Demonstration Queries (Ubuntu Lab)
Go to Graph tab.
8.1 Check targets
up
8.2 CPU usage (%)
100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
8.3 Memory usage (%)
(node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes)
/ node_memory_MemTotal_bytes * 100
8.4 Disk usage (%)
100 * (1 - (node_filesystem_avail_bytes{mountpoint="/"}
/ node_filesystem_size_bytes{mountpoint="/"}))
Node Exporter exposes system metrics on port 9100
Prometheus scrapes metrics on intervals
If Targets are UP, monitoring is working
Security Groups control access, not Linux
10οΈβ£ What We Deliberately Allowed (Lab Mode)
| Component | Allowed |
|---|---|
| SG inbound | All traffic |
| IPv4 | 0.0.0.0/0 |
| Ports | 9090, 9100 |
β Easy learning
β Not secure for prod
π Grafana Placement & Setup (Ubuntu, AWS EC2)
πΉ WHERE does Grafana go?
π Grafana is installed on the MONITOR EC2, together with Prometheus.
Final architecture (very important)
TARGET EC2 (Ubuntu)
βββ Node Exporter
βββ :9100 (/metrics)
MONITOR EC2 (Ubuntu)
βββ Prometheus
β βββ :9090 (scrapes node exporter)
βββ Grafana
βββ :3000 (visualizes Prometheus data)
Why Grafana goes on MONITOR EC2
- Grafana does NOT collect metrics
- Grafana only visualizes
- Prometheus is the data source
-
Putting Grafana next to Prometheus:
- simpler networking
- real production pattern
- easier teaching
β
Correct: Prometheus + Grafana on same EC2
β Wrong: Grafana on target node
π§© STEP-BY-STEP: Install Grafana on Ubuntu (MONITOR EC2)
1οΈβ£ Connect to MONITOR EC2
ssh ubuntu@<MONITOR_PUBLIC_IP>
2οΈβ£ Update system
sudo apt update
3οΈβ£ Install required packages
sudo apt install -y apt-transport-https software-properties-common wget
4οΈβ£ Add Grafana GPG key
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
Expected:
OK
5οΈβ£ Add Grafana repository
echo "deb https://packages.grafana.com/oss/deb stable main" | \
sudo tee /etc/apt/sources.list.d/grafana.list
6οΈβ£ Install Grafana
sudo apt update
sudo apt install -y grafana
7οΈβ£ Start & enable Grafana
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
Check status:
sudo systemctl status grafana-server
Expected:
Active: active (running)
8οΈβ£ Open Grafana port in Security Group (LAB MODE)
On MONITOR EC2 Security Group, ensure inbound rule exists:
| Type | Protocol | Port | Source |
|---|---|---|---|
| All traffic | All | All | 0.0.0.0/0 |
(You already allowed all traffic, so Grafana will open automatically.)
9οΈβ£ Access Grafana UI
From your browser:
http://<MONITOR_PUBLIC_IP>:3000
Default login
-
Username:
admin -
Password:
admin - Youβll be asked to set a new password
π Connect Grafana to Prometheus
10οΈβ£ Add Prometheus as Data Source
In Grafana UI:
- βοΈ Settings
- Data Sources
- Add data source
- Select Prometheus
Configure:
- Name: Prometheus
- URL:
http://localhost:9090
- Click Save & Test
Expected:
Data source is working
π Import Node Exporter Dashboard (DEMO GOLD)
11οΈβ£ Import Dashboard ID 1860
- Click + (Create) β Import
- Enter Dashboard ID:
1860
- Click Load
- Select Prometheus as data source
- Click Import
π You now see:
- CPU usage
- Memory usage
- Disk usage
- Network traffic
- Load average
This is the industry-standard Node Exporter dashboard.
Prometheus collects metrics
Grafana visualizes metrics
Node Exporter exposes system data
Targets UP = data is flowing
- Prometheus β Status β Targets (UP)
- Grafana β Dashboard β live graphs
π§ Common Issues & Fixes
Grafana page doesnβt open
- Check port 3000 in Security Group
- Check service:
sudo systemctl status grafana-server
No data in Grafana
- Check Prometheus data source URL
- Must be:
http://localhost:9090
Dashboard empty
- Prometheus targets must be UP
- Wait 1β2 minutes (data fills over time)
π§ͺ DEVOPS LAB: Node Exporter β Prometheus β Grafana
π΄ LAB SETUP (MANDATORY CONTEXT)
You have 2 Ubuntu EC2 servers:
π’ SERVER 1 β TARGET (Application / Infra Node)
- Ubuntu
- Runs Node Exporter
- Port: 9100
- Purpose: Expose system metrics
π’ SERVER 2 β MONITOR (Observability Node)
- Ubuntu
- Runs Prometheus
- Runs Grafana
-
Ports:
- 9090 β Prometheus
- 3000 β Grafana
Purpose: Collect + Visualize metrics
πΉ PART 1 β NODE EXPORTER (TARGET SERVER)
β Goal
Prove:
- Metrics exist
- They are machine-readable
- Node Exporter does NOT store data
π WHERE
π SSH into TARGET server
ssh ubuntu@<TARGET_PUBLIC_IP>
π§Ύ WHAT TO TYPE
1οΈβ£ Check Node Exporter is running
ps -ef | grep node_exporter
β WHAT YOU SHOULD SEE
/usr/local/bin/node_exporter
π DEVOPS ANALYSIS
β Exporter is running
β Metrics endpoint should exist
2οΈβ£ Check port 9100
ss -tulnp | grep 9100
β EXPECTED OUTPUT
LISTEN 0 4096 *:9100
π DEVOPS ANALYSIS
β Node Exporter is reachable
β Ready to be scraped
3οΈβ£ View raw metrics
curl http://localhost:9100/metrics | head
β EXPECTED OUTPUT
# HELP node_cpu_seconds_total ...
# TYPE node_cpu_seconds_total counter
π DEVOPS ANALYSIS (VERY IMPORTANT)
β Hard to read
β No history
β No visualization
β Conclusion: Node Exporter only exposes current values
πΉ PART 2 β PROMETHEUS (MONITOR SERVER)
β Goal
Prove:
- Prometheus pulls metrics
- Stores time-series data
- Knows target health
π WHERE
π SSH into MONITOR server
ssh ubuntu@<MONITOR_PUBLIC_IP>
π§Ύ WHAT TO TYPE
4οΈβ£ Confirm Prometheus is running
ps -ef | grep prometheus
β EXPECTED OUTPUT
/usr/local/bin/prometheus
π DEVOPS ANALYSIS
β Prometheus engine is active
5οΈβ£ Open Prometheus UI (BROWSER)
http://<MONITOR_PUBLIC_IP>:9090
6οΈβ£ Check scrape status
UI β Status β Targets
β EXPECTED UI STATE
node UP
prometheus UP
π DEVOPS ANALYSIS (CRITICAL)
| State | Meaning |
|---|---|
| UP | Prometheus can scrape |
| DOWN | Network / exporter issue |
This page is the FIRST place DevOps checks.
πΉ PART 3 β PROMQL (HOW DEVOPS QUERIES DATA)
π WHERE
π Prometheus UI β Graph
7οΈβ£ Check system health
up
β EXPECTED RESULT
node = 1
prometheus = 1
π DEVOPS ANALYSIS
β Monitoring pipeline is healthy
8οΈβ£ Inspect CPU metrics
node_cpu_seconds_total
π DEVOPS ANALYSIS
β Raw counter
β Not useful directly
9οΈβ£ Calculate CPU usage (%)
100 - (
avg by (instance) (
rate(node_cpu_seconds_total{mode="idle"}[5m])
) * 100
)
β EXPECTED OUTPUT
Graph showing CPU %
π DEVOPS ANALYSIS
β Detect CPU saturation
β Identify performance issues
π Memory usage
(node_memory_MemTotal_bytes -
node_memory_MemAvailable_bytes)
/ node_memory_MemTotal_bytes * 100
π DEVOPS ANALYSIS
β Memory leaks
β Capacity planning
1οΈβ£1οΈβ£ Disk usage
100 * (1 -
node_filesystem_avail_bytes{mountpoint="/"} /
node_filesystem_size_bytes{mountpoint="/"})
π DEVOPS ANALYSIS
β Disk full = production outage risk
πΉ PART 4 β WHY PROMETHEUS UI IS NOT ENOUGH
β QUESTION TO STUDENTS
Can you easily compare CPU + Memory + Disk?
Answer: β NO
π DEVOPS CONCLUSION
Prometheus = database & engine, not dashboards
πΉ PART 5 β GRAFANA (VISUALIZATION)
π WHERE
π Browser
http://<MONITOR_PUBLIC_IP>:3000
Login:
admin / admin
1οΈβ£2οΈβ£ Add Prometheus datasource
Grafana β Settings β Data Sources β Prometheus
URL:
http://localhost:9090
Click Save & Test
π DEVOPS ANALYSIS
β Grafana can query Prometheus
1οΈβ£3οΈβ£ Import dashboard
Grafana β Create β Import
Dashboard ID:
1860
β WHAT YOU SHOULD SEE
- CPU graphs
- Memory graphs
- Disk graphs
- Network graphs
π DEVOPS ANALYSIS
β One screen
β Real-time visibility
β Executive-friendly dashboards
πΉ PART 6 β FAILURE ANALYSIS (REAL DEVOPS TEST)
π WHERE
π TARGET server
1οΈβ£4οΈβ£ Stop Node Exporter
sudo systemctl stop node_exporter
π WHERE
π Prometheus UI β Targets
β EXPECTED
node β DOWN
π WHERE
π Grafana dashboard
β EXPECTED
- Graphs freeze
- No new data
π DEVOPS ANALYSIS (MOST IMPORTANT SKILL)
| Symptom | Conclusion |
|---|---|
| Target DOWN | Exporter or network |
| Grafana empty | Upstream issue |
| Prometheus UP | Collector fine |
1οΈβ£5οΈβ£ Restore service
sudo systemctl start node_exporter
Targets β UP again
π§ FINAL DEVOPS TAKEAWAYS (MEMORIZE)
Node Exporter exposes metrics
Prometheus pulls and stores metrics
PromQL analyzes metrics
Grafana visualizes metrics
Targets page = first troubleshooting step
Top comments (0)