Prometheus: Metrics, Labels and Time Series
A time series is one number measured again and again over time. Prometheus stores every number as a time series with a name and a set of labels.
One metric, four series
The same metric name with different labels is a different series each time.
http_requests_total{route="/",status="200"} 41
http_requests_total{route="/api/orders",status="200"} 39Read one series by its labels
A query names the metric and the labels it wants, and gets one series back.
up{job="shopsentry"}Labels on a host metric
Node Exporter labels CPU time by mode, so idle time is a separate series from busy time.
node_cpu_seconds_total{cpu="0",mode="idle"} 1447.93Example
curl -s "http://127.0.0.1:19101/api/v1/query?query=http_requests_total"Key points
- A time series is a stream of values for one thing, each value stamped with a time.
- A metric name says what is measured, like http_requests_total.
- A label is a named tag on a series, like route="/api/orders" or status="200".
- Labels turn one metric into many series, one per combination of label values.
- A series is named by its metric name plus its full set of labels.
- Too many label values makes too many series, which slows Prometheus down.
In this example, one query for http_requests_total returns four series, one per route. The labels method, route and status tell the series apart, and the values 41, 39, 39 and 13 are the counts so far. Without the route label, the four series would collapse into one number and the per-route question could not be answered.
Note
A label value that changes on every request, like a user id, is a bad label.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What makes two series with the same metric name different from each other?