Introduction to Monitoring with Prometheus & Grafana
You can't fix what you can't see β monitoring is how you see.
Shipping software is only half the job β you also need to know itβs healthy once itβs running. Is the app slow? Is memory creeping up? Did errors just spike after that deploy? Monitoring answers these questions in real time, and Prometheus + Grafana are the most popular open-source pair for doing it.
π― Learning Objectives
By the end of this lesson you will:
- Understand why monitoring is essential in DevOps
- Know the difference between metrics, logs, and traces
- Understand what Prometheus and Grafana each do
- See how they fit together into a monitoring stack
Why Monitor at All?
Without monitoring you find out about problems from angry users, not your dashboards. Good monitoring lets you:
- Detect issues before customers do
- Diagnose the cause quickly instead of guessing
- Decide when to scale up or down based on real load
- Prove your system meets its reliability targets (SLOs)
π‘ Observability in one sentence
Monitoring tells you that something is wrong; observability helps you understand why. Metrics, logs, and traces together give you observability.
The Three Pillars of Observability
| Pillar | Answers | Example tool |
|---|---|---|
| Metrics | βHow much / how many / how fast?β (numbers over time) | Prometheus |
| Logs | βWhat exactly happened, in detail?β | Loki, ELK |
| Traces | βWhere did the time go across services?β | Zipkin, Jaeger |
This section is about metrics β lightweight numeric measurements sampled over time, like CPU usage, request rate, or error count.
What is Prometheus?
Prometheus is a time-series database and monitoring system. Its job is to collect and store metrics, and let you query them.
Its defining feature is the pull model: instead of your apps pushing data out, Prometheus reaches out and scrapes an HTTP endpoint (usually /metrics) on each target on a schedule.
ββββββββββββββ scrape /metrics ββββββββββββββββ
β Your App β βββββββββββββββββββ β Prometheus β
β (exposes β β (stores + β
β /metrics) β βββββββββββββββββββΆ β queries) β
ββββββββββββββ numeric samples ββββββββββββββββMetrics look like simple text β a name, optional labels, and a value:
http_requests_total{method="GET",status="200"} 1027
http_requests_total{method="GET",status="500"} 3
process_cpu_seconds_total 4412.5The {...} part holds labels β dimensions you can filter and group by later.
What is Grafana?
Prometheus stores numbers, but staring at raw numbers is painful. Grafana is the visualization layer: it connects to Prometheus (and many other sources) and turns those metrics into dashboards β graphs, gauges, and tables β plus alerts.
| Tool | Role |
|---|---|
| Prometheus | Collects, stores, and queries metrics |
| Grafana | Visualizes metrics and builds dashboards |
Together they form the classic open-source monitoring stack: Prometheus is the engine, Grafana is the windshield.
The Full Picture
Apps + Exporters ββ/metricsβββΆ Prometheus ββqueriesβββΆ Grafana βββΆ You
β
ββββΆ Alertmanager βββΆ Slack / email / PagerDutyAn exporter is a small helper that exposes metrics for things that canβt do it themselves (a database, a Linux host, etc.). Weβll meet those next.
π§ͺ Hands-on Lab
Spot the Metric
Given this scrape output, answer: how many total GET requests returned a server error (status 500)?
http_requests_total{method="GET",status="200"} 1027
http_requests_total{method="GET",status="500"} 3
http_requests_total{method="POST",status="200"} 88π§ Knowledge Check
How does Prometheus collect metrics from targets by default?
What is Grafana's main job in this stack?
πΌ Interview Preparation
Why is Prometheus's pull model useful in dynamic environments like Kubernetes?
Summary
You now understand why we monitor, the difference between metrics, logs, and traces, and the roles of Prometheus (collect + store + query) and Grafana (visualize + alert). Next, weβll go hands-on with Prometheus itself: scraping, the data model, and querying with PromQL.