Let's start from basics.
Time series
In Prometheus time series is a series of (timestamp, value)
pairs ordered by timestamp
. The value
can contain only numeric values (either integer or fractional).
Every time series in Prometheus has a name. For example, temperature
or requests_total
. Additionally, every time series can have a set of {key="value"}
labels. For example, temperature{city="Paris"}
or requests_total{instance="host123",job="foo_app"}
.
A time series is uniquely identified by its name plus its labels. For example, temperature{city="Paris"}
and temperature{city="London"}
are two different time series, since they differ by city
label value.
Side note: time series name can be referred as __name__
pseudo-label in Prometheus. So, temperature{city="Paris"}
and {__name__="temperature",city="Paris"}
refer to the same time series.
Series selector
Prometheus allows using e.g. series selectors for selecting time series matching these selectors. For example, temperature
selector selects all the time series with the name temperature
, while {city=~"London|Paris"}
selects all the time series with the label city
containing either London
or Paris
values.
Counter
Counter is a time series starting from zero and containing non-decreasing sequence of values over time. The only exception is when the counter resets to zero after service restart. Counters are usually used for counting some events such as served requests. For example, http_requests_total{method="GET",path="/foo/bar"}
counts the number of GET
requests served at /foo/bar
path.
Prometheus provides useful functions for counter metrics such as rate() and increase():
increase(m[d])
calculates the increase of counters matching m
series selector over the given lookbehind window d
. For example, increase(http_requests_total[1h])
returns the number of requests over the last hour for time series with the name http_requests_total
. It returns results individually per each time series matching m
.
rate(m[d])
calculates the average per-second increase rate for counter metrics matching m
series selector over the given lookbehind window d
. For example, rate(http_requests_total[1h])
calculates the average per-second requests rate over the last hour for time series with the name http_requests_total
.
Important note: increase()
and rate()
functions expect only counters as their input. If you pass non-counter time series to these functions, then they may return unexpected (aka garbage) results.
Other metric types
Prometheus supports other metric type. See the list of supported metrics types
Additional information
The following articles contain additional useful information for Prometheus newbies:
P.S. Prometheus concepts such as range vector
and instant vector
are very confusing. That's why I don't recommend using them. See this answer for details.