Time Series & Labels
Series identity, samples, and cardinality
Prometheus stores exactly one kind of thing: time series. Everything else, PromQL included, is built on that one idea, so it's worth being precise about it.
What identifies a series
A time series is identified by its metric name plus its full set of labels. Change any label value and you have a different series.
http_requests_total{job="demo-app", route="/api/orders", status="200"} # series A
http_requests_total{job="demo-app", route="/api/orders", status="500"} # series B
http_requests_total{job="demo-app", route="/api/search", status="200"} # series CInternally, the metric name is just another label called __name__. These
two selectors are identical:
http_requests_total{route="/api/orders"}
{__name__="http_requests_total", route="/api/orders"}Each series is a list of samples. A sample is a pair: a millisecond timestamp and a 64-bit float. That's all. There are no strings, no integers, and no nulls. A missing value is simply a missing sample.
http_requests_total{job="demo-app", route="/api/orders", status="200"}
@1791783000.000 18233
@1791783015.000 18527
@1791783030.000 18802
...Labels whose names start with __ are internal. __name__ is kept;
others like __address__, __scheme__, __metrics_path__, and
__meta_* (from service discovery) exist only during relabeling and are
dropped before storage. That's how you can use discovery metadata to
build labels without storing it. See
Service Discovery & Relabeling.
Cardinality
Cardinality is the number of distinct series. For one metric, it's roughly the product of the number of values each label takes:
http_requests_total
method: 1 (GET)
route: 4 (/, /api/orders, /api/search, other)
status: ~5 (200, 404, 500, 503, ...)
instance: 1
-> about 1 x 4 x 5 x 1 = 20 series (only combinations that actually occur are created)Now add a histogram with 10 buckets. Every label combination gets 13
series: the 10 configured buckets, the implicit le="+Inf" bucket, plus
_count and _sum. Scale the service to 50 instances and you have
thousands of series from one metric. That's fine. Prometheus handles
millions.
The problem is unbounded labels:
| Label | Values | Verdict |
|---|---|---|
status | ~10 HTTP codes | Fine |
route | Your route templates, e.g. /users/:id | Fine |
path | Every raw URL, e.g. /users/18237 | Unbounded. One series per user. |
user_id, email, order_id, trace_id | One per entity | Unbounded |
error_message | Free text | Unbounded, and changes when code changes |
The demo app maps raw paths to a fixed set of routes and labels anything
unknown as route="other". Look for this in demo-app/app.py. Without
it, any client could request /a, /b, /c, ... and create a new
series per request. That's a real way to take down a Prometheus server
from the internet.
Why cardinality is the cost
Every active series costs memory in the head block, roughly 3-4 KB including its index entries, whether it receives one sample a minute or four. Disk cost depends on samples, but samples compress very well (about 1-2 bytes each). So:
- Memory scales with active series.
- Disk scales with series × samples per series × retention.
- Query time scales with how many series a query touches.
That's why the first question in any Prometheus capacity discussion is "how many series?", not "how many requests?". Full detail in Retention & Capacity.
Measuring it yourself
# total active series
prometheus_tsdb_head_series
# top 10 metrics by series count
topk(10, count by (__name__) ({__name__=~".+"}))
# series per job
sum by (job) (scrape_samples_post_metric_relabeling)
# how many distinct routes does the demo app expose?
count(count by (route) (http_requests_total))The Status → TSDB status page in the Prometheus UI shows the same
breakdown, plus which label names have the most distinct values. Run
the topk query now and look at the result. Histogram buckets will be
near the top. They usually are.
Staleness
When a series stops appearing in scrapes, because the target died or the app stopped exposing it, Prometheus writes a special stale marker sample. Queries treat the series as gone from that point on.
Without staleness markers, a query at time t looks back up to 5 minutes (the lookback delta) for the most recent sample. That's why a series that just stops without a marker, for example data pushed with explicit timestamps, can appear to "hang" on its last value for 5 minutes before disappearing.
Treat label sets as part of your API. Renaming a label or changing its values breaks every dashboard, recording rule, and alert that selects on it, silently. A broken selector doesn't error, it just returns nothing, and an alert on "nothing" never fires.
Next: the four metric types and what each one can tell you. Metric Types.