nadavgam
nadavgam

Reputation: 2422

Trying to understand prometheus data model in a more simplified way and how does rate function work

I'm trying to understand the basics of Prometheus and after reading the official docs and a few blogs, I'm still not sure what the data model is at its core. For now I'm referring only to Counters

What I understand

So thats what I understand, I'm sure its not accurate :/ So I would love if someone can shed some light on these topics..

Upvotes: 5

Views: 7531

Answers (1)

valyala
valyala

Reputation: 18056

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.

Upvotes: 17

Related Questions