Pcornel
Browse topics
Options
Recent
Favorites
Observability · Technical reference

Cardinality

Direct answer

Cardinality is the number of unique label combinations (time series) for a metric. Unbounded labels such as user ID, request ID or full URL explode memory and cost.

When to use this

Use it when Prometheus memory grows or queries get slow.

First 30 seconds

1. Top metrics by series: topk(10, count by (__name__)({__name__=~".+"})).

2. TSDB status page (head series, label value counts).

3. Find the offending label.

4. Drop or rewrite with metric_relabel_configs.

5. Fix the instrumentation.

Operational verification

label values × labels → series count → memory/cost

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
OpenTelemetry / Prometheus / Grafana / common metrics-log-trace pipelines
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformOpenTelemetry / Prometheus / Grafana / common metrics-log-trace pipelines
Scope / prerequisiteUse it when Prometheus memory grows or queries get slow.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 How to verify Verify boundary

Watch series count after each deployment. Use relabelling to drop risky labels at scrape time.

Step 2 Common failures Narrow the fault

A new label with request paths can multiply series overnight. Histograms multiply series by the number of buckets. Dropping a label at query time does not reduce storage.

Key points

Labels must have bounded values. Use templates for paths (/users/:id). Find top series in the TSDB status page and drop labels with relabelling.

Key checks
  • topk(10, count by (__name__)({__name__=~".+"})) — first check for this topic
  • curl -s localhost:9090/-/ready — Prometheus ready
  • curl -s 'localhost:9090/api/v1/query?query=up' — scrape targets up/down
  • promtool check config prometheus.yml — config valid
ReferenceWhat it is1 section · depth on demand

How it works

Time-series databases keep an index entry and memory for every active series. A label with a thousand values on a metric with ten other combinations creates ten thousand series. Log systems with indexed fields face the same issue.

ReferenceImportant terms & boundaries3 sections · depth on demand

Controlling cardinality

Each unique combination of labels is a separate time series. A label like user_id, request_id or full URL path can create millions of series and crash Prometheus or raise costs.

  • Use bounded labels (status code, route template, region).
  • Put unbounded values in logs or traces, or as exemplars.
  • Find the worst metrics: topk(10, count by (__name__) ({__name__=~".+"})) or the TSDB status page.
  • Drop or relabel labels in the scrape config or collector.

In depth

How fast series multiply

Series count is the product of the distinct values of every label on a metric:

http_requests_total{method, code, route, instance} = 5 methods × 8 codes × 60 routes × 20 instances = 48,000 series.

Turn that into a histogram with 12 buckets (plus _sum and _count) and it becomes about 670,000 series — from one metric. Add user_id and it is unbounded.

Rules for labels

Good labelBad label
Bounded, known set: method, status_class, route (template, /orders/{id})Unbounded: user_id, request_id, email, full URL with IDs
Needed for queries or alerts"Might be useful some day"
Stable over timeChanges every deploy (pod hash in long-lived metrics)

Values that are unique per request belong in logs, traces or exemplars, not in metric labels.

Finding the offenders

topk(10, count by (__name__) ({__name__=~".+"}))                 # metrics with most series
count by (route) (http_requests_total)                             # values of one label
curl -s localhost:9090/api/v1/status/tsdb | jq '.data.seriesCountByMetricName[:10], .data.labelValueCountByLabelName[:10]'
promtool tsdb analyze /prometheus      # offline, on a copy of the data directory

Controlling it at ingest

metric_relabel_configs:
- action: labeldrop
  regex: request_id|session_id
- source_labels: [__name__]
  regex: 'go_gc_.*'
  action: drop

Set sample_limit (and label_limit) per scrape job so one bad deployment fails its own scrape instead of taking down the whole Prometheus.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • User IDs or request IDs as metric labels.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
cardinalitymetric cardinalityprometheus series explosion
Confirmation

Confirm action

Continue?