Need Help Extracting Label Values / Querying

143 views
Skip to first unread message

IndGirl6

unread,
Aug 1, 2018, 5:52:28 PM8/1/18
to Prometheus Users
Hi,

Trying to build / templatize a dashboard for SNMP devices.
My SNMP scrape output shows the following set of data:

ifDescr{ifDescr="fc1/29",ifIndex="16891904"} 1
ifDescr{ifDescr="fc1/30",ifIndex="16896000"} 1
ifDescr{ifDescr="fc1/31",ifIndex="16900096"} 1
ifDescr{ifDescr="fc1/32",ifIndex="16904192"} 1


in my dashboard template i already have a variable for "ifindex".
I want to now create another variable for ifDescr. So basically, what i want is when we select an ifindex, it should show me the ifDescr.

i have been trying:
query_result(ifDescr{ifindex="$ifindex"},ifDescr)
also tried the same with label_value.
BUt no luck with both of these..

PS: very new to Prometheus / Grafana, getting a good hang of it, but getting past Querying is my biggest pain.

Thanks
IG6

Chris Marchbanks

unread,
Aug 1, 2018, 7:32:49 PM8/1/18
to IndGirl6, Prometheus Users
Hello,

For your example, trying something like the following should get values for ifDescr.
query: query_result(ifDescr{ifIndex="$ifindex"})
regex: /ifDescr=\"([^\"]+)\"/

If you have more than one metric per ifDescr label, then add some sort of aggregation to remove duplicate values, such as:
query_result(count(ifDescr{ifindex="$ifindex"}) by (ifDescr))

Hope this helps!

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/a0c219a3-ec54-4661-b92f-6867a2caede9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Chris Marchbanks | Engineer
FreshTracks.io - Intelligent Alerting for Kubernetes and Prometheus

IndGirl6

unread,
Aug 2, 2018, 8:06:13 AM8/2/18
to Prometheus Users
Hi Chris 
thanks fro your response, i did try that but the query itself gives me no results.

i did make some progress with the following Query and regex (which i copied from somewhere):
Query: query_result(ifDescr)
 the above query gives me the following results:

ifDescr{ifDescr="Control Plane Interface",ifIndex="567",instance="172.16.70.1",job="snmp"} 1 1533211417000
ifDescr{ifDescr="EOBC0/0",ifIndex="392",instance="172.16.70.1",job="snmp"} 1 1533211417000
ifDescr{ifDescr="Ethernet1/1",ifIndex="436207616",instance="172.16.148.21",job="snmp"} 1 1533211417000

regex: .*ifDescr="(.*?)",.*
with the above regex, the results are:
Control Plane Interface
EOBC0/0
Ethernet1/1
Ethernet1/1/1
Ethernet1/1/10
Ethernet1/1/11
Ethernet1/1/12
Ethernet1/1/13
Ethernet1/1/14
Ethernet1/1/15

This is what i was originally looking for, but now i want to EXCLUDE "Ethernet*" and "vethernet*"

Does any one know how i can go ahead and exclude that?

thanks
IG6
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To post to this group, send email to promethe...@googlegroups.com.

Chris Marchbanks

unread,
Aug 2, 2018, 12:37:16 PM8/2/18
to IndGirl6, Prometheus Users
I am glad you made progress!

Modifying your query to exclude the regex matches you do not want would be best. 
You can do this using the "!~" matcher (more information: https://prometheus.io/docs/prometheus/latest/querying/basics/)
For example: ifDescr{ifDescr!~".*thernet.*"}

To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/91474973-6035-4163-b296-bd236e09342a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages