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.
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.
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.
$interval is a built in automatic variable in grafana , and is automatically set based on time range.
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.
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.
Possible starting from Grafana 6.0, use this snippet:
Url: "/dashboard-id/dashboard-name?var-variable1=${__cell}&from=$__from&to=$__to
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With