Understanding Prometheus — Monitoring Made Easy (Part-4)

 In the previous blog, we deployed an EC2 instance, ran our application inside a Docker container, and installed cAdvisor and Prometheus.

 (If you missed it, the link to the previous blog)

Part-1: https://brillertechnologies.blogspot.com/2025/11/prometheus-and-grafana-projectpart-1-by.html

Part 2: https://brillertechnologies.blogspot.com/2025/11/monitoring-containers-with-cadvisorpart.html

Part 3: https://brillertechnologies.blogspot.com/2025/12/understanding-prometheus-in-simple-way.html

Today, we will go one step ahead and understand how Prometheus actually works, how it collects metrics, and how we can add new jobs like cAdvisor and Node Exporter.



1. Understanding Prometheus Targets

After installing Prometheus, open the Prometheus UI:

<IP>:9090

Click on:

Status → Targets

Here you will see all jobs defined in your prometheus.yml file.

You will also see a job named Prometheus.
 Prometheus scrapes its own metrics using:

localhost:9090

We use localhost because Prometheus itself is running in the same container on port 9090.

2. Viewing Prometheus Metrics

To see the raw metrics Prometheus exposes, open:

<IP>:9090/metrics

This page shows hundreds of Prometheus internal metrics.

3. Adding cAdvisor Job in Prometheus

Now let’s add the cAdvisor job so Prometheus can collect Docker container metrics.

Open the Prometheus config file:

vim prometheus.yml

Add the following job:

- job_name: "Docker Containers"
static_configs:
- targets: ["cadvisor:8080"]
  • cadvisor → container name
  • 8080 → cAdvisor port

Save and exit:

:wq

Restart Prometheus container

Only Prometheus needs to restart so it can reload the new job:

docker restart <prometheus-container-id>

Now go to:

Status → Targets

You will see the new Docker Containers job.

4. Running Queries in Prometheus

Prometheus allows you to run queries using PromQL.

Example:

rate(container_cpu_usage_seconds_total{name="notes-todo"}[5m])

What this query does?

This query shows:

  • The CPU usage
  • For the notes-todo container
  • For the last 5 minutes

You can view the result in table form or graph form.

You can also reduce the time window, for example:

[1m]

5. Adding Node Exporter (System Metrics)

Now, let’s run Node Exporter to collect OS-level metrics like CPU, RAM, Disk, Network etc.

Node Exporter works very similar to eBPF — it collects information directly from the Linux kernel.

Add Node Exporter in docker-compose

Open docker-compose:

vim docker-compose.yml

Add:

node-exporter:
image: prom/node-exporter:latest
container_name: node-exporter
restart: unless-stopped
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- '--path.procfs=/host/proc'
- '--path.rootfs=/rootfs'
- '--path.sysfs=/host/sys'
- '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
ports:
- "9100:9100"
expose:
- 9100
networks:
- monitoring

Save and exit:

:wq

Now start the Node Exporter container:

docker compose up -d

6. Allow Port 9100

Go to AWS → EC2 → Security Group → Inbound Rules
 Open port:

9100

Now go to:

<IP>:9100

You will see Node Exporter running.
 You will also see a Metrics button — these metrics will be scraped by Prometheus.

7. Add Node Exporter Job in Prometheus

Open Prometheus config again:

vim prometheus.yml

Add:

- job_name: "Node-Exporter"
static_configs:
- targets: ["node-exporter:9100"]

Save and exit.

Restart Prometheus:

docker restart <prometheus-container-id>

Now check Status → Targets and you will see the new Node Exporter job.

8. Useful PromQL Queries for Demo

You can use this prompt in ChatGPT to generate more queries:

Prompt:
 Act as an expert in PromQL. You have a Prometheus server with Node Exporter metrics configured. Create some PromQL queries for demo purposes.

Here are a few ready-made examples:

CPU Usage

rate(node_cpu_seconds_total{mode!="idle"}[5m])

Memory Usage

node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes

Disk Usage

node_filesystem_avail_bytes{mountpoint="/"}

Network Receive Bytes

rate(node_network_receive_bytes_total[5m])

Network Transmit Bytes

rate(node_network_transmit_bytes_total[5m])

You can paste these queries directly into Prometheus and view results.

Conclusion

Today, we learned:

✔ How Prometheus discovers jobs
 ✔ How to add cAdvisor and Node Exporter
 ✔ How to restart Prometheus to reload config
 ✔ How to run PromQL queries
 ✔ How to demonstrate metrics to learners

I hope you liked today’s blog.
 Feel free to share it with others who want to learn DevOps monitoring!

🌐 Online References


Comments

Popular posts from this blog

📘 Understanding Prometheus in a Simple Way-Part 3 (For DevOps Beginners)

Grafana Setup & Dashboard Creation (Part-5)— Explained by Raees Yaqoob Qazi

My First Python Program: A Simple Calculator