13.4 Primary path — Prometheus + Node Exporter + Grafana
Why: the problem
Zomato runs thousands of servers. No engineer can log in to each one and type top. They need one place that collects numbers from every server, keeps them for weeks and draws graphs. The most popular free stack for this is Prometheus, Node Exporter and Grafana. Node Exporter sits on each server and shows its numbers on a web page. Prometheus visits that page every 15 seconds and saves the numbers with time. Grafana reads Prometheus and draws beautiful dashboards. Think of it like a school: Node Exporter is each student writing marks on a slate, Prometheus is the teacher who collects the slates every 15 seconds into a register, and Grafana is the report card the parents see. Companies like Swiggy, Razorpay and many Infosys and TCS projects use this stack, and Kubernetes clusters almost always come with it. That is why this is the main path of this chapter.
What we will build
You will start the full stack with one Docker Compose file on a single Ubuntu VM: Prometheus, Node Exporter and Grafana. Then you will open each one and see the data flow from server to graph. Next you will add a second server to watch. Finally you will run the same stack without Docker using Ubuntu packages, which is how many old company servers do it.
What: every term in plain English
- Prometheus — A free database for metrics. It pulls numbers from targets and stores them with time.
- Exporter — A small program that shows a system's numbers on a /metrics web page.
- Node Exporter — The exporter for Linux machines: CPU, memory, disk, network.
- Grafana — A web app that draws graphs and dashboards from Prometheus and many other sources.
- Scrape — One visit by Prometheus to a /metrics page to read the numbers.
- Target — One address Prometheus scrapes, like 10.0.1.12:9100.
- Pull model — Prometheus goes and asks for numbers. Servers do not push them.
- TSDB — Time series database. Stores number + time, again and again.
How: step by step
-
Install Docker and Compose
sudo apt-get update && sudo apt-get install -y docker.io docker-compose-v2What it does: Docker runs the three tools as containers.
Output
Setting up docker.io (24.0.7) ... -
Make the stack folder
mkdir -p ~/monstack && cd ~/monstackWhat it does: Files for the stack live here.
Output
(no output) -
Write the two files
Create compose.yaml and prometheus.yml from Example 1What it does: Compose runs three services. prometheus.yml tells Prometheus what to scrape.
Output
(no output) -
Start the stack
sudo docker compose up -dWhat it does: Pulls images and starts three containers.
Output
Container monstack-prometheus-1 Started Container monstack-node-exporter-1 Started Container monstack-grafana-1 Started -
Open Prometheus targets
Browser: http://SERVER_IP:9090/targetsWhat it does: Both jobs must be UP.
Output
node (1/1 up) prometheus (1/1 up) -
Open Grafana
Browser: http://SERVER_IP:3000 (user admin, the password from compose.yaml)What it does: Log in and change the password.
Output
Welcome to Grafana
Example 1: The full stack in one Compose file
Stack. Docker Compose, Prometheus, Node Exporter, Grafana
Goal. The full stack in one Compose file.
compose.yaml
services:
prometheus:
image: prom/prometheus:v2.54.1
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prom-data:/prometheus
ports:
- "9090:9090"
node-exporter:
image: prom/node-exporter:v1.8.2
pid: host
volumes:
- /:/host:ro,rslave
command: ["--path.rootfs=/host"]
ports:
- "9100:9100"
grafana:
image: grafana/grafana:11.2.0
environment:
- GF_SECURITY_ADMIN_PASSWORD=change-me
volumes:
- grafana-data:/var/lib/grafana
ports:
- "3000:3000"
volumes:
prom-data:
grafana-data:
prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ["localhost:9090"]
- job_name: node
static_configs:
- targets: ["node-exporter:9100"]
labels:
env: lab
What each line does
image: prom/prometheus:v2.54.1— A fixed version. Never use latest in real work../prometheus.yml:/etc/prometheus/prometheus.yml:ro— Mounts our config into the container, read only.prom-data:/prometheus— A named volume, so metrics survive a restart.pid: host— Node Exporter sees the real host processes, not only the container.--path.rootfs=/host— Read disk numbers from the host root, mounted at /host.GF_SECURITY_ADMIN_PASSWORD— First Grafana admin password. Change it after login. Never commit a real one.scrape_interval: 15s— Prometheus reads every target every 15 seconds.targets: ["node-exporter:9100"]— Compose gives each service a DNS name, so we use the service name.
Green output
$ sudo docker compose ps
NAME IMAGE STATUS PORTS
monstack-grafana-1 grafana/grafana:11.2.0 Up 20 seconds 0.0.0.0:3000->3000/tcp
monstack-node-exporter-1 prom/node-exporter:v1.8.2 Up 20 seconds 0.0.0.0:9100->9100/tcp
monstack-prometheus-1 prom/prometheus:v2.54.1 Up 20 seconds 0.0.0.0:9090->9090/tcp
Expected result. Three containers are up. The full monitoring stack took less than one minute.
Example 2: Follow one number from the server to the graph
Stack. curl, Prometheus HTTP API
Goal. Follow one number from the server to the graph.
Commands
# 1. The exporter page (the student's slate)
curl -s localhost:9100/metrics | grep "^node_filesystem_avail_bytes" | head -2
# 2. Ask Prometheus (the teacher's register) with its HTTP API
curl -s "localhost:9090/api/v1/query?query=node_load1" | python3 -m json.tool
# 3. Check the targets from the command line
curl -s localhost:9090/api/v1/targets | grep -o '"health":"[a-z]*"'
What each line does
localhost:9100/metrics— Raw numbers from Node Exporter, in plain text.node_filesystem_avail_bytes— Free bytes on each disk./api/v1/query?query=node_load1— Asks Prometheus for the latest value of node_load1.python3 -m json.tool— Prints the JSON nicely."health":"up"— Prometheus could scrape the target last time.
Green output
node_filesystem_avail_bytes{device="/dev/xvda1",fstype="ext4",mountpoint="/"} 6.4e+09
{
"status": "success",
"data": {
"resultType": "vector",
"result": [
{
"metric": {"__name__": "node_load1", "env": "lab", "instance": "node-exporter:9100", "job": "node"},
"value": [1761406800.123, "0.21"]
}
]
}
}
"health":"up"
"health":"up"
Expected result. The same number lives on the exporter page, inside Prometheus with labels job, instance and env, and soon on a Grafana graph.
Example 3: Watch a second server and run the stack without Docker
Stack. Ubuntu 24.04 packages, AWS security groups
Goal. Watch a second server and run the stack without Docker.
On the second server (Ubuntu)
sudo apt-get update && sudo apt-get install -y prometheus-node-exporter
systemctl status prometheus-node-exporter --no-pager
curl -s localhost:9100/metrics | grep -c "^node_"
Add it to prometheus.yml on the monitoring server
- job_name: node
static_configs:
- targets: ["node-exporter:9100"]
labels: {env: lab}
- targets: ["10.0.1.25:9100"]
labels: {env: lab, role: web}
Reload Prometheus
sudo docker compose restart prometheus
# Or on a package install of Prometheus:
# sudo apt-get install -y prometheus && sudo systemctl reload prometheus
What each line does
prometheus-node-exporter— The Ubuntu package. It installs a systemd service on port 9100.grep -c "^node_"— Counts how many node metrics the exporter shows.10.0.1.25:9100— The private IP of the second server.labels: {env: lab, role: web}— Extra tags, so dashboards can filter by role.docker compose restart prometheus— Prometheus reads the new config at start.
Green output
Active: active (running) since Sun 2026-10-25 21:40:11 IST
1187
Targets page:
node (2/2 up)
http://node-exporter:9100/metrics UP env=lab
http://10.0.1.25:9100/metrics UP env=lab role=web
Expected result. Two servers are now watched from one Prometheus. The security group of the second server must allow port 9100 only from the monitoring server.
Verify: did it work?
-
All containers up?
sudo docker compose ps --format "{{.Name}} {{.Status}}"What it does: Every line must say Up.
Output
monstack-grafana-1 Up 2 minutes monstack-node-exporter-1 Up 2 minutes monstack-prometheus-1 Up 2 minutes -
Any target down?
curl -s localhost:9090/api/v1/targets | grep -c '"health":"down"'What it does: Must print 0.
Output
0
When it is red 1
Get "http://10.0.1.25:9100/metrics": context deadline exceeded
Cause. Prometheus cannot reach the second server. Usually a security group or firewall blocks 9100.
Fix, step by step
- In AWS, add an inbound rule TCP 9100 from the monitoring server security group.
- On the server, check: sudo ss -ltnp | grep 9100
- Test from the monitoring server: curl -s 10.0.1.25:9100/metrics | head -3
When it is red 2
Error loading config ... yaml: line 7: did not find expected key
Cause. prometheus.yml has wrong spaces. YAML needs exact indentation with spaces, not tabs.
Fix, step by step
- Run: sudo docker run --rm -v $PWD:/c --entrypoint promtool prom/prometheus:v2.54.1 check config /c/prometheus.yml
- Fix the line it shows.
- Restart Prometheus.
When it is red 3
Grafana: Invalid username or password
Cause. You changed the env password after the first start. Grafana keeps the first one in its volume.
Fix, step by step
- Reset: sudo docker compose exec grafana grafana cli admin reset-admin-password NEW_PASS
- Log in with NEW_PASS.
- Store it in your password manager.
Cleanup
-
Stop the stack, keep data
sudo docker compose downWhat it does: Stops containers. Volumes stay.
Output
Container monstack-grafana-1 Removed ... -
Remove everything
sudo docker compose down -vWhat it does: Also deletes stored metrics and dashboards.
Output
Volume monstack_prom-data Removed Volume monstack_grafana-data Removed
Ravindra Bagale's Tip
Node Exporter is the student, Prometheus is the teacher register, Grafana is the report card. One Compose file starts it all in a minute.
Node Exporter विद्यार्थी, Prometheus शिक्षक register, Grafana report card. एक compose file ने सगळं एक मिनिटात चालू होतं.
Node Exporter छात्र, Prometheus शिक्षक register, Grafana report card. एक compose file से सब एक मिनट में चालू.
Practice tasks
Easy Pin and list versions
Why: Fixed versions make your lab repeatable.
What to do: Write down the three image versions you used.
- sudo docker compose images
Check: Three fixed tags, no latest.
Medium Add cAdvisor
Why: Container metrics need a different exporter.
What to do: Add the gcr.io/cadvisor/cadvisor service on port 8080 and a scrape job for it.
- Mount /var/run, /sys and /var/lib/docker read only.
- Add job_name: cadvisor.
Check: Targets shows cadvisor UP.
Hard Lock down ports
Why: Exporters leak details about your servers if open to the internet.
What to do: Allow 9100 only from the Prometheus server and 3000 only from your office IP.
- Edit AWS security groups.
- Test from outside with curl; it must time out.
Check: Only allowed IPs can reach the ports.
Easy Say the Prometheus stack in two lines
Why: If you can say it simply, you understand it. Juniors and interviewers both want the short version first.
What to do: Write two short lines about the Prometheus stack for a fresher who knows only Linux, Git and Docker basics.
- Write the problem it solves.
- Write the one command, query or config line you use for it.
- Read it aloud to a friend.
Check: A fresher understands it without asking a question.
Easy Keep a throwaway monitoring lab
Why: Practice needs a lab you can break. If it gets messy, you delete the containers and start again in one minute.
What to do: Run Node Exporter in Docker and read its metrics page.
- docker run -d --name ne -p 9100:9100 prom/node-exporter
- curl -s localhost:9100/metrics | grep node_load1
- docker rm -f ne
Check: You see a line that starts with node_load1 and a number.
Medium Do it on a second stack
Why: Monitoring ideas must work on Prometheus and on CloudWatch. Only the tool changes, not the thinking.
What to do: Repeat this lesson on a different stack than the one you used first.
- If you used Prometheus, try the CloudWatch console or AWS CLI.
- Keep the same question: is it up, is it fast, is it failing, is it full?
- Compare the two graphs side by side.
Check: Both tools answer the same question with a number and a graph.
Medium Break it on purpose
Why: You must know the red error by face. During an outage there is no time to read slowly.
What to do: Cause one error from the "When it is red" part of this lesson and fix it.
- Follow the error section.
- Copy the exact message into your notes.
- Write the fix in one line.
Check: You fixed it using only the steps, without searching the web.
Medium Write a one-page runbook
Why: At 2 a.m. nobody remembers PromQL. A short page saves the on-call person.
What to do: Write a one-page runbook for this lesson.
- Title, when the alert fires, the graph to open, the exact commands, how to check, how to undo.
Check: A teammate can follow it alone, without calling you.
Hard Explain it like an interview
Why: Interviewers want real stories, not definitions.
What to do: Record a 60 second answer about this lesson.
- Say the problem, the metric you watched, the number you saw and the fix.
Check: Your answer has a real metric name and a real number.
Hard Draw the flow top to bottom
Why: A drawing shows where a number is born and where it ends up.
What to do: Draw this lesson as boxes from top to bottom.
- Start at the server or app, go through the exporter, Prometheus or CloudWatch, then Grafana, then the alert on your phone.
Check: Each box matches a real command or file in this lesson.
Homework: try at home
Try at home
At home, run the Compose stack on your laptop with Docker Desktop or on a free-tier EC2. Leave it for one day. Next day open Prometheus and query node_load1 for the last 24 hours. You will see your own machine's day as a graph.
Recap
- Node Exporter shows host numbers; Prometheus scrapes and stores them; Grafana draws them.
- Prometheus pulls every scrape_interval, usually 15 seconds.
- One Compose file starts the whole stack in a minute.
- Add more servers as targets with labels.
- Keep exporter ports closed to the internet.
FAQ
Can Prometheus store data for a year?
It can, but most teams keep 15 to 30 days locally and use Thanos, Mimir or Amazon Managed Prometheus for long term.
Do I need Grafana?
Prometheus has a basic graph page. Grafana is far better for teams.
Is this stack free?
Yes, all three are open source. Grafana Cloud and AWS also sell managed versions.
What about Windows servers?
Use windows_exporter on port 9182.
Can Prometheus scrape over the internet?
It can, but use a VPN or private network, or put the exporter behind TLS and basic auth.
Interview questions
-
Explain the Prometheus architecture.
Exporters expose metrics over HTTP; Prometheus scrapes them on an interval, stores them in its TSDB, evaluates rules and sends alerts to Alertmanager; Grafana queries it for dashboards.
-
Pull vs push monitoring?
Pull (Prometheus) knows when a target is down and controls load. Push (CloudWatch agent, StatsD) works better for short jobs and behind firewalls. Prometheus has Pushgateway for batch jobs.
-
What is an exporter?
A program that converts a system's stats into Prometheus text format on /metrics.
-
How do you add a new server to Prometheus?
Install node exporter, open port 9100 to Prometheus, add the target to scrape_configs or use service discovery like ec2_sd_configs, then reload.
-
What ports do Prometheus, Grafana and Node Exporter use?
9090, 3000 and 9100.
Quick quiz
Q1. What does Node Exporter do?
It shows Linux host numbers on a /metrics page.
Q2. Does Prometheus push or pull?
Pull. It scrapes targets.
Q3. Default port of Node Exporter?
9100.
Q4. Default port of Grafana?
3000.
Q5. Where do you see if a target is up?
Prometheus Status, then Targets, or /api/v1/targets.
Did you understand? Let us try it once more.
Revision card
Interview card