Remember that the $var syntax is part of Grafana, not part of Prometheus.  
All the variables are substituted before the Prometheus even sees the query.

Maybe something like this would work (I've never tried it):
up{instance=~"$instance"}  == $state

where $state is set to 0 or 1.  But that's probably not what you want, as 
there's no "all" option.

Your question is about Grafana and how it handles local variables and 
drop-down selections, and how those variables interact with each other. You 
should be asking Grafana experts about whether it's possible in Grafana to 
configure what you want, and if so, how.  Prometheus is the database 
backend, and simply answers the queries that Grafana sends to it.

On Tuesday, 13 September 2022 at 04:29:13 UTC+1 [email protected] 
wrote:

> I have an "N" number of servers. for example, let the value of N is 100. 
> Out of 100 60 are reachable, 30 are unreachable, and the remaining 10 
> servers are in another database. So in the grafana dashboard, I want to add 
> a variable as a filter, so if I click that filter the promql should be able 
> to get the records as per the requirement. 
>
> Like the filter dropdown will be All, Reachable Unreachable.
> The query should be like  "up{instance=~"$instance"}  some regex/filters"
>
> so whenever I click from the grafana filter(All/Reachable/Unreachable), 
> then the query should automatically change with respect to the regex/filter 
> we used. Is that possible?
>
> Thanks & regards,
> Bharath Kumar.
> On Monday, 12 September 2022 at 23:56:42 UTC+5:30 Brian Candler wrote:
>
>> up{instance=~"$instance"} == 1 == 0     # technically valid expression, 
>> but useless because it always gives zero results
>>
>> What are you actually trying to do?  If this is something to do with 
>> Grafana then you're probably going about it the wrong way. In particular, 
>> Grafana lets you build a single panel with multiple queries.
>>
>> On Monday, 12 September 2022 at 14:56:25 UTC+1 [email protected] 
>> wrote:
>>
>>> Hello all,
>>>
>>> Can we apply filters in the prometheus query?
>>>
>>> I had a query up{instance=~"$instance"}
>>>
>>> for reachable up{instance=~"$instance"} == 1
>>> for unreachable up{instance=~"$instance"} == 0
>>>
>>> Can I combine the above two queries conditions (==0 and ==1) in a single 
>>> query?
>>>
>>> Thanks & regards,
>>> Bharath Kumar.
>>>
>>>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/0347e1cb-3b8b-4ea0-ab2f-1a79061669b9n%40googlegroups.com.

Reply via email to