Prometheus does not return divide result as a list

24 views
Skip to first unread message

ricardo....@edge.com.py

unread,
Jan 25, 2021, 6:08:54 PM1/25/21
to Prometheus Users
Hell Guys 
I have a doubts about using arithmetic operations in Prometheus
Currently I have a metric A that return more than a single row with values, so when I try to divide these values of A by using the single result of another metric B I get as result only one row instead of many row as the first metric A, but when I put the value in hard code, I get the result I want it i.e.  many row as the first metric A
Why is this happening?
Thanks for your help in advance 

Stuart Clark

unread,
Jan 25, 2021, 6:23:11 PM1/25/21
to ricardo....@edge.com.py, Prometheus Users

With many operations Prometheus will match the metrics using their labels. For your example of A & B, take a look at what combinations of labels exist - both could be single values or multiple values, both could have identical sets of labels or different ones. These will all alter the outcome.

For division by a fixed number there is no problem with label matching, so for example A / 5 will return exactly as you'd expect, being each of the values of A (which could be multiple combinations of labels) divided by 5.

Ricardo Estalder

unread,
Jan 25, 2021, 6:39:37 PM1/25/21
to Stuart Clark, Prometheus Users
I think this is very complicated due The first query A returns 10 rows with label: metric_name A B C ... and the other query B, for example returns the sum of values of query A without labels so how will these match each other?

Stuart Clark

unread,
Jan 26, 2021, 4:12:20 AM1/26/21
to Ricardo Estalder, Prometheus Users
On 25/01/2021 23:42, Ricardo Estalder wrote:
> I think this is very complicated due The first query A returns 10 rows
> with label: metric_name A B C ... and the other query B, for example
> returns the sum of values of query A without labels so how will these
> match each other?
>
If there are no matches you wouldn't get things returned.

Take a look at the vector matching documentation for more details:

https://prometheus.io/docs/prometheus/latest/querying/operators/#vector-matching

Ricardo Estalder

unread,
Jan 26, 2021, 8:36:07 AM1/26/21
to Stuart Clark, Prometheus Users
Thanks for your reply i resolved using group_left 
Reply all
Reply to author
Forward
0 new messages