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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With