Is it possible to definie variable template with regex?

Hi,

I want to create a variable template based on maching one column. I explain : i have dataset with column host like this

host
fr.hostname1
fr.hostname2
us.hostname3
uk.hostname4
uk.hostname5

The two fisrt caracter refer to country and i want to create a variable template “country” to select only data of that country.

Is it possible with grafana? I use influxdb database.

Thanks

It very easy to do that with influxdb query in command line. the query like this :slight_smile:

 select * from data where host =~ /us-.*/ limit 5;
1 Like

yes, it is possible using the Regex field under Query options. The trick is to using a capturing group:

/(..).*/

for a query that would be something like this in your case:

SHOW TAG VALUES WITH KEY = "host"

This would capture the first two characters for every value and match on everything. You can be much more specific if you want to filter out values. The above regex for your host list would return: fr, us, uk

You can then use the above template variable in your query:

select * from data where host =~ /$tempvar.*/ limit 5;

Read more about templating with InfluxDB here: http://docs.grafana.org/features/datasources/influxdb/#templating

2 Likes

Thanks @daniellee. It’s work fine

1 Like

@daniellee : Hi , can you tell me how can i remove any 1 value from drop down using regex or query in variables.

i have below 3 values to display currently in Page dropdown :

  • Build_Status
  • login
  • logout

i want to remove Build_status . Can i use in query “NOT EQUAL TO” or can you tell me how to use regex for this ?