Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine separate timeseries labels in Prometheus query?

I have the following timeseries entries.

ifDescr{ifDescr="GigabitEthernet1/1",ifIndex="1",instance="x.x.x.x",job="snmp"} 1
ifDescr{ifDescr="GigabitEthernet1/2",ifIndex="2",instance="x.x.x.x",job="snmp"} 1
ifDescr{ifDescr="GigabitEthernet5/3",ifIndex="3",instance="x.x.x.x",job="snmp"}
ifHCInOctets{ifIndex="1",instance="x.x.x.x",job="snmp"}
ifHCInOctets{ifIndex="2",instance="x.x.x.x",job="snmp"}
ifHCInOctets{ifIndex="2",instance="x.x.x.x",job="snmp"}

As is, I have no way of telling which index matches which description, which makes things confusing.

Is there a way to basically to do a join of the above labels using ifIndex to correlate to the the ifDesc label? Or maybe the job can be used to tie the two timeseries together?

I have looked at the group_left feature but haven't been able to figure out how to get it working to combine/aggregate labels.

like image 853
jmreicha Avatar asked May 14 '18 20:05

jmreicha


People also ask

How can we join two metrics in a Prometheus query?

PromQL supports the ability to join two metrics together: You can append a label set from one metric and append it to another at query time. This can be useful in Prometheus rule evaluations, since it lets you generate a new metric for a series by appending labels from another info metric.

What is Group_left in Prometheus?

This is where group_left comes in. It says that for each set of matching labels, many time series on the left hand side can match with just one time series on the right hand side. It'll then perform the binary operation, and keep all the labels of the left hand side. This gives us the expression.

How do you use the wildcard in Prometheus query?

Prometheus uses the tilde character ~ to indicate a query contains a wildcard. Inside the label-query the "dot plus" ( . + ) character combination is used where all characters are accepted.


1 Answers

In this case you want something like rate(ifHCInOctets[5m]) * ignoring(ifDescr) group_left(ifDescr) ifDescr

explanation:

Prometheus will only let you use grouping on operations between series. The value of ifDescr is always "1" so it's safe to multiply.

The ignoring clause means don't use the ifDescr label for matching (as it's only on one of the series). ifIndex, instance and job will be used.

group_left is specifying what labels you want from the series ifDescr. In this case they have the same names.

<vector expr> <bin-op> ignoring(<label list>) group_left(<label list>) <vector expr>

reference: https://prometheus.io/docs/prometheus/latest/querying/operators/#many-to-one-and-one-to-many-vector-matches

like image 168
brian-brazil Avatar answered Sep 28 '22 15:09

brian-brazil