# Prometheus and Grafana

> Collect metrics with Prometheus, query them with PromQL, and build dashboards in Grafana that people actually use. Free notes, key concepts, resources and a...

Canonical: https://www.internhack.in/roadmaps/tracks/devops/prometheus-grafana
Last updated: 2026-11-28

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](https://www.internhack.in/roadmaps/tracks/devops/observability-fundamentals), [Kubernetes Architecture and kubectl](https://www.internhack.in/roadmaps/tracks/devops/kubernetes-architecture)

**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 `/metrics` endpoints 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_exporter` for hosts, `blackbox_exporter` for 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](https://prometheus.io/docs/introduction/overview/) (Prometheus)
- [Querying Prometheus](https://prometheus.io/docs/prometheus/latest/querying/basics/) (Prometheus)
- [Grafana documentation](https://grafana.com/docs/grafana/latest/) (Grafana Labs)

Previous: [Observability Fundamentals](https://www.internhack.in/roadmaps/tracks/devops/observability-fundamentals) · Next: [Centralised Logging with Loki](https://www.internhack.in/roadmaps/tracks/devops/loki-logging)

## More in Observability: Metrics, Logs, Traces and SLOs

- [Observability Fundamentals](https://www.internhack.in/roadmaps/tracks/devops/observability-fundamentals)
- [Prometheus and Grafana](https://www.internhack.in/roadmaps/tracks/devops/prometheus-grafana)
- [Centralised Logging with Loki](https://www.internhack.in/roadmaps/tracks/devops/loki-logging)
- [Elastic Stack (ELK) and OpenSearch](https://www.internhack.in/roadmaps/tracks/devops/elk-stack)
- [Distributed Tracing with OpenTelemetry](https://www.internhack.in/roadmaps/tracks/devops/tracing-opentelemetry)
- [Alerting That Does Not Burn People Out](https://www.internhack.in/roadmaps/tracks/devops/alerting)
- [SLIs, SLOs and Error Budgets](https://www.internhack.in/roadmaps/tracks/devops/slo-error-budgets)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [DevOps Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/devops)
