Use it when Prometheus memory grows or queries get slow.
Cardinality
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.
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.
label values × labels → series count → memory/cost
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
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.
Labels must have bounded values. Use templates for paths (/users/:id). Find top series in the TSDB status page and drop labels with relabelling.
topk(10, count by (__name__)({__name__=~".+"}))— first check for this topiccurl -s localhost:9090/-/ready— Prometheus readycurl -s 'localhost:9090/api/v1/query?query=up'— scrape targets up/downpromtool 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 label | Bad 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 time | Changes 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.
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
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.