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

1

5

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

  • Time series is defined by data type(lets assume that its counter for now) and labels
  • For example, if we have two labels, label A and label B, then the number of different time series will be the number of values A can have multiple the number value B can have(|A|x|B| in short)
  • One view of these time series is an Instant Vector
    • if Prometheus samples every one hour, will have a vector each hour, the vector size would be |A|x|B| or |B| if we set a value to label A
    • we can say that it's a 'time series of vectors'?
  • Another view is a Range Vector
    • now each vector is more like a Matrix? size of (number of samples in the time range)* |A|x|B|?
    • rate function takes most recent sample in the range, subtracts the first sample and divides by the number of seconds in that time range?

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

Gastrology answered 12/9, 2022 at 8:55 Comment(0)
S
14

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.

Slice answered 13/9, 2022 at 14:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.