Course contentsShow
← Cloud and Infrastructure
Lesson 1955 of 2,98942. Observability - MetricsFree lesson

Labels and Dimensionality

Leveraging labels to add dimensions to metrics for filtering, grouping, and creating flexible dashboards.

Labels and Dimensionality

What you'll learn: How to use Prometheus labels to transform flat metrics into multi-dimensional data that you can slice, filter, and aggregate in powerful ways.

The Core Idea

In Prometheus, labels are key-value pairs attached to metrics that add dimensions to your time-series data. Think of a basic metric like http_requests_total as a single number. Now imagine adding labels like {method="GET", status="200", endpoint="/api/users"} — suddenly that single metric becomes a rich, multi-dimensional dataset you can query from any angle.

Labels are what make Prometheus metrics flexible and powerful. Without them, you'd need a separate metric for every combination (like http_requests_get_200, http_requests_post_404, etc.). With labels, one metric name can represent thousands of unique time-series, each identified by its unique label combination.

How Dimensionality Works

Each unique combination of labels creates a distinct time-series. For example:

http_requests_total{method="GET", status="200"}
http_requests_total{method="POST", status="200"}
http_requests_total{method="GET", status="404"}

These are three separate time-series under one metric name. This dimensionality lets you:

  • Filter: Show only GET requests
  • Group: Aggregate all 200 statuses across methods
  • Pivot: Compare behavior across endpoints or regions

The Analogy

Think of labels like spreadsheet columns. A basic counter is just a single number. Labels turn it into a table where you can sort, filter, and create pivot tables — except Prometheus does this at massive scale over time.

Watch the Cardinality

Each label combination creates storage overhead. Labels like user_id or request_id with thousands of unique values create high cardinality, which can overwhelm Prometheus. Stick to labels with bounded, predictable values.

Key Takeaway: Labels transform metrics from simple numbers into multi-dimensional datasets, enabling flexible filtering and grouping — but choose dimensions wisely to avoid cardinality explosions.