How to sum by according to dynamically changing description?

14 views
Skip to first unread message

Umut Cokbilir

unread,
Jan 22, 2022, 1:59:38 AMJan 22
to Prometheus Users
Hello Everyone,

How to sum according to "@...@" on ifAlias which changes dynamically in addition to this ifAlias are not totally same but @..@ are same on ifAlias.
if they are same, I want to aggregate them. I tried to query below which is not so dynamic.

sum by (instance) (rate(ifHCInOctets{ifAlias=~"^QinQ_.*020000026586.*_NNI.*"}[10m]) * 8) and on(instance) sysName{sysName =~ ".*$name.*"}

How to make dynamic like if they x combine them, if they are y combine them, etc.

{ifAlias="QinQ_BTS_B4965_ABIS@020000026586@||TT/ME-200-10000||_NNI_BKD", ifDescr="GigabitEthernet3/1/0.2068", ifIndex="494", instance="10.85.7.2", job="ptn"}
{ifAlias="QinQ_NodeB_B4965@020000026586@||TT/ME-200-10000||_NNI_BKD", ifDescr="GigabitEthernet3/1/0.1088", ifIndex="495", instance="10.85.7.2", job="ptn"}
{ifAlias="QinQ_eNodeB_B4965_OAM@020000026586@||TT/ME-200-10000||_NNI_BKD", ifDescr="GigabitEthernet3/1/0.3662", ifIndex="493", instance="10.85.7.2", job="ptn"}
{ifAlias="QinQ_eNodeB_B4965_S1_X2@020000026586@||TT/ME-200-10000||_NNI_BKD", ifDescr="GigabitEthernet3/1/0.3661", ifIndex="492", instance="10.85.7.2", job="ptn"}

{ifAlias="QinQ_BTS_C1623_ABIS@020000026587@||TT/ME-200-10000||_NNI_BKD", ifDescr="GigabitEthernet3/1/0.2067", ifIndex="496", instance="10.85.7.2", job="ptn"}
{ifAlias="QinQ_NodeB_C1623@020000026587@||TT/ME-200-10000||_NNI_BKD", ifDescr="GigabitEthernet3/1/0.1098", ifIndex="497", instance="10.85.7.2", job="ptn"}
{ifAlias="QinQ_eNodeB_C1623_OAM@020000026587@||TT/ME-200-10000||_NNI_BKD", ifDescr="GigabitEthernet3/1/0.3663", ifIndex="498", instance="10.85.7.2", job="ptn"}
{ifAlias="QinQ_eNodeB_C1623_S1_X2@020000026587@||TT/ME-200-10000||_NNI_BKD", ifDescr="GigabitEthernet3/1/0.3664", ifIndex="499", instance="10.85.7.2", job="ptn"}

Thanks.

Brian Candler

unread,
Jan 22, 2022, 4:37:58 AMJan 22
to Prometheus Users
Try adding a new label using label_replace, e.g.

label_replace(ifHCInOctets, "vid", "$1", "ifAlias", ".*@(.+)@.*")

When that works, you can start using it in a subexpression:

    sum by (vid) ( label_replace(rate(ifHCInOctets[10m]), "vid", "$1", "ifAlias", ".*@(.+)@.*") )

If you're doing this a lot, you might want to add the new label at scrape time using a metric rewriting rule, or generate some new timeseries using a recording rule.
Reply all
Reply to author
Forward
0 new messages