Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the Grafana time interval range for DrillDown links to an ElasticSearch page

I'm trying to add a drilldown link to an Elastic search link in a Grafana chart. I'm able to use the variables that are already defined in my panel, but I also want to make use of the current time interval when creating the URL for elastic search.

I have tried using the following variables in the URL based on different online posts, hoping that they would be replaced by Grafana when the URL is clicked.

  • $__interval
  • $timeInterval
  • $interval

but, nonw have been converted to the time range value that is currently selected.

e.g.: Url in Grafana:

https://elastic.local.dev/app/kibana#/discover?_g=(refreshInterval:(pause:!t,value:10000),time:(from:now-$__interval,mode:quick,to:now))&_a=(columns:!(_source),index:'logs-*',interval:auto,query:(language:lucene,query:'severity:FATAL%20AND%20%20environment:$environment'),sort:!('@timestamp',desc))

Expected Url when user clicks the chart:

https://elastic.local.dev/app/kibana#/discover?_g=(refreshInterval:(pause:!t,value:10000),time:(from:now-1h,mode:quick,to:now))&_a=(columns:!(_source),index:'logs-*',interval:auto,query:(language:lucene,query:'severity:FATAL%20AND%20%20environment:Development'),sort:!('@timestamp',desc))

Actual Url when user clicks the chart:

https://elastic.local.dev/app/kibana#/discover?_g=(refreshInterval:(pause:!t,value:10000),time:(from:now-$__interval,mode:quick,to:now))&_a=(columns:!(_source),index:'logs-*',interval:auto,query:(language:lucene,query:'severity:FATAL%20AND%20%20environment:Development'),sort:!('@timestamp',desc))

The $environment variable is being replaced as expected but the $__interval variable is not being replaced which causes the URL to not be parsed correctly by Elastic Search when trying to display the page.

Drilldown link for SingleStat Chart

like image 713
EndlessSpace Avatar asked Nov 08 '18 15:11

EndlessSpace


People also ask

How do you change the time interval in Grafana?

You can enter exact time values or relative values, such as now-24h , and then choose Apply time range. Choose the From or To field. Amazon Managed Grafana displays a calendar. Choose the day or days that you want to use as the current time range and then choose Apply time range.

What is $_ interval in Grafana?

$interval is a built in automatic variable in grafana , and is automatically set based on time range.

How do I connect ElasticSearch to Grafana?

Add ElasticSearch data source Now login to the Grafana web GUI at http://<server>:3000, and select “Data Sources” from the menu. Click on “Add data source”. Type “myelasticsearch” for the name and select “Elasticsearch” from the type pulldown. The URL value should be the ElasticSearch server on the default port 9200.

How do I use variables in Grafana query?

Define a new Grafana variable To create a new variable, go to your Grafana dashboard settings, navigate to the 'Variable' option in the side-menu, and then click the 'Add variable' button. In this case, we use the 'Query' type, where your variable is defined as the results of SQL query.


1 Answers

Possible starting from Grafana 6.0, use this snippet:

Url: "/dashboard-id/dashboard-name?var-variable1=${__cell}&from=$__from&to=$__to

like image 186
user2650367 Avatar answered Oct 13 '22 08:10

user2650367