Learn Labs
Data Model & Metric Types

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 C

Internally, 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
...

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:

LabelValuesVerdict
status~10 HTTP codesFine
routeYour route templates, e.g. /users/:idFine
pathEvery raw URL, e.g. /users/18237Unbounded. One series per user.
user_id, email, order_id, trace_idOne per entityUnbounded
error_messageFree textUnbounded, and changes when code changes

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.

Next: the four metric types and what each one can tell you. Metric Types.

On this page