Prometheus and Grafana
Collect metrics with Prometheus, query them with PromQL, and build dashboards in Grafana that people actually use.
Intermediate · about 10 hours · difficulty 3/5
Learn first: Observability Fundamentals, Kubernetes Architecture and kubectl
Prometheus is the standard open-source metrics system, especially in Kubernetes, and Grafana is the standard way to visualise it.
How Prometheus works
- It scrapes HTTP
/metricsendpoints on an interval and stores samples in a local time-series database. - Targets come from static config or service discovery (Kubernetes, EC2, Consul).
- Exporters expose metrics for things that do not speak Prometheus:
node_exporterfor hosts,blackbox_exporterfor probes, exporters for Postgres, Redis and nginx. - Metric types: counter (only goes up), gauge (goes up and down), histogram and summary (distributions).
PromQL essentials
rate(http_requests_total[5m]): per-second rate of a counter.sum by (status) (...): aggregate across labels.histogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket[5m]))): p95 latency.- Recording rules precompute expensive queries; alerting rules fire when an expression holds for a duration.
In Kubernetes
The kube-prometheus-stack Helm chart installs the Prometheus Operator, Alertmanager, Grafana and ready-made dashboards. ServiceMonitor and PodMonitor objects declare what to scrape.
Scaling and retention
A single Prometheus is not built for years of data or global views. Thanos, Grafana Mimir or VictoriaMetrics add long-term storage and federation; managed options exist on every cloud.
Grafana
Build dashboards around questions (is the service healthy? where is time spent?), use variables for environment and service, store dashboards as JSON in Git, and add deploy annotations.
Good enough to move on: you can instrument an app, scrape it in Kubernetes with a ServiceMonitor, write PromQL for rate, error ratio and p95 latency, and build a RED dashboard with variables.
Key concepts
- Scraping and service discovery
- Metric types
- Exporters
- PromQL: rate, sum, histogram_quantile
- Recording and alerting rules
- kube-prometheus-stack and ServiceMonitors
- Grafana dashboards and variables
- Long-term storage: Thanos, Mimir
Mini project
Install kube-prometheus-stack on a local cluster, expose custom request metrics from a small app, scrape them with a ServiceMonitor, and build a Grafana dashboard showing rate, error percentage and p95 latency per endpoint.
Check yourself
Why do you apply rate() to a counter instead of graphing its raw value?
Free resources
- Prometheus documentation (Prometheus)
- Querying Prometheus (Prometheus)
- Grafana documentation (Grafana Labs)