Grafana templating with prometheus

28 views
Skip to first unread message

BHARATH KUMAR

unread,
Jul 28, 2022, 3:08:47 AM7/28/22
to Prometheus Users
Hi all,

In grafana dashboard I want to create a template variable.

up==0 so that this will give the info which instances are down.

but while declaring up==0, I am getting an error like you should not use operators while declaring grafana templates.

Is there anyway to declare?

Thanks & regards,
Bharath Kumar.

Brian Candler

unread,
Jul 28, 2022, 4:55:56 AM7/28/22
to Prometheus Users
This is a discussion group for Prometheus, so questions about Grafana would be best directed to the Grafana community: https://community.grafana.com/

In any case, you haven't shown exactly what you've tried to do.

I do know there are special template queries for Grafana variables. Here are a couple of examples I've pulled from a local dashboard:

Name: instance
Type: Query
Data source: prometheus
Query: label_values(ifOperStatus, instance)

Name: ifName
Type: Query
Data source: prometheus
Query: query_result(ifOperStatus{instance="$instance"})
Regex: /.*ifName="([^"]+)".*/

I would have thought you could use query_result(up==0), since that's a valid PromQL query, and you could pull out the label you want (e.g. instance) using a Regex as shown.

But if that doesn't work, then please ask on a Grafana forum.
Reply all
Reply to author
Forward
0 new messages