Prometheus Query In Grafana Template

1,303 views
Skip to first unread message

Emmanuel Yong

unread,
Jun 1, 2017, 8:03:06 PM6/1/17
to Prometheus Users
Dear All,

Currently I Am trying To Monitor The Traffic Of All My Company Cisco Switches, Having Issues Matching The IP Address of the Switch To the Hostname.

I am using Grafana Templating To Do So, and below are my Templating:

When I Try $Hostname, it does return the device hostname but is not in the format which i want, how can i make sure it just return XXXXXXXXX.PH01.COM
sysName{instance="10.5.2.12",job="cisco_snmp",sysName="XXXXXXXX.PH01.COM"} 1 1496361351000

$Hostnamequery_result(sysName{instance='$Device'})
$Interfacelabel_values({job='cisco_snmp',instance=~'$Device'}, interface)
$Devicelabel_values({job="cisco_snmp"},instance)

Ben Kochie

unread,
Jun 2, 2017, 1:38:31 AM6/2/17
to Emmanuel Yong, Prometheus Users
You probably want to use label_values(sysName{instance="$Device"}, sysName)

Your label_values() functions above should probably use a metric name like sysName

$device = label_values(sysName{job="cisco_snmp"}, instance)

Otherwise Prometheus will search all metric names in order to produce the device, this could be very slow.

--
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/6a9c3e74-23bb-4952-b19f-e662e55cf349%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Kochie

unread,
Jun 2, 2017, 1:40:29 AM6/2/17
to Emmanuel Yong, Prometheus Users
I'd also recommend fixing your DNS such that you don't need to extract the hostname from sysName.  You want XXXXXXXXX.PH01.COM to be used for the instance value in the prometheus config.

Emmanuel Yong

unread,
Jun 2, 2017, 1:44:00 AM6/2/17
to Prometheus Users, yongem...@gmail.com
Awesome Ben, This Is Lifesaver as I Was Pondering on RegEx.

This is a very good tip

BTW, are there any option for me to combine $device and $name together? So that user when select a device, it will show the appropriate hostname?

$Devicelabel_values({job="cisco_snmp"},instance)
Duplicate Edit
$Interfacequery_result(ifHCInOctets{job="cisco_snmp",instance="$Device"})Duplicate Edit
$Namelabel_values(sysName{instance='$Device'},sysName)

On Friday, June 2, 2017 at 1:40:29 PM UTC+8, Ben Kochie wrote:
I'd also recommend fixing your DNS such that you don't need to extract the hostname from sysName.  You want XXXXXXXXX.PH01.COM to be used for the instance value in the prometheus config.
On Fri, Jun 2, 2017 at 7:38 AM, Ben Kochie <sup...@gmail.com> wrote:
You probably want to use label_values(sysName{instance="$Device"}, sysName)

Your label_values() functions above should probably use a metric name like sysName

$device = label_values(sysName{job="cisco_snmp"}, instance)

Otherwise Prometheus will search all metric names in order to produce the device, this could be very slow.
On Fri, Jun 2, 2017 at 2:03 AM, Emmanuel Yong <yongem...@gmail.com> wrote:
Dear All,

Currently I Am trying To Monitor The Traffic Of All My Company Cisco Switches, Having Issues Matching The IP Address of the Switch To the Hostname.

I am using Grafana Templating To Do So, and below are my Templating:

When I Try $Hostname, it does return the device hostname but is not in the format which i want, how can i make sure it just return XXXXXXXXX.PH01.COM
sysName{instance="10.5.2.12",job="cisco_snmp",sysName="XXXXXXXX.PH01.COM"} 1 1496361351000

$Hostnamequery_result(sysName{instance='$Device'})
$Interfacelabel_values({job='cisco_snmp',instance=~'$Device'}, interface)
$Devicelabel_values({job="cisco_snmp"},instance)

--
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-use...@googlegroups.com.
To post to this group, send email to promethe...@googlegroups.com.

Ben Kochie

unread,
Jun 2, 2017, 1:51:38 AM6/2/17
to Emmanuel Yong, Prometheus Users
On Fri, Jun 2, 2017 at 7:44 AM, Emmanuel Yong <yongem...@gmail.com> wrote:
Awesome Ben, This Is Lifesaver as I Was Pondering on RegEx.

This is a very good tip

BTW, are there any option for me to combine $device and $name together? So that user when select a device, it will show the appropriate hostname?

This needs to be done ahead of time by having DNS match the sysName and using that for instance in the prometheus config instead of raw IPs.
 
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/0abaef5e-b2f7-482c-8da6-8c031f496f77%40googlegroups.com.

Emmanuel Yong

unread,
Jun 2, 2017, 5:56:19 AM6/2/17
to Prometheus Users, yongem...@gmail.com
Hi,

i already done dns resolution and from prometheus i am able to see the data using the DNS name but under grafana if i use DNS name i am unable to retrieve the list of available instances but if i use IP address, i can get list of interface

What am i doing wrong?

Thank You

Emmanuel Yong

unread,
Jun 2, 2017, 5:58:02 AM6/2/17
to Prometheus Users, yongem...@gmail.com
{"status":"error","errorType":"bad_data","error":"parse error at char 13: could not parse remaining input \"({job=\\\"cisco_sn\"..."}

this is what i am seeing from

http://grafana-internal:9090/api/v1/series?match[]=label_values(%7Bjob%3D%22cisco_snmp%22%2Cinstance%3D%22OPB48L1-CS29SW05%22%7D)&start=1496396747&end=1496397047

Ben Kochie

unread,
Jun 2, 2017, 6:46:41 AM6/2/17
to Emmanuel Yong, Prometheus Users
Can you share a copy of the prometheus.yml?

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/26907665-e7c6-4ced-95e9-5f8b7e2e694d%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages