Grafana: global variables to access [from,to] values of the time range

14k views Asked by At

I am doing some tests with a MySQL data-source and make use of the timefilter inside the SQL query:

// my query goes here...
WHERE $__timeFilter(time_start);

which generates something like the following:

WHERE time_start >= FROM_UNIXTIME(1505207821) AND time_start <= FROM_UNIXTIME(1505229421);

Are there any variables that can give me access to the 2 timestamps that define the time range?

For instance, at the example above:

from = 1505207821
to = 1505229421
2

There are 2 answers

4
Daniel Lee On BEST ANSWER

Yes, $__timeFrom() and $__timeTo() if you are using the latest 4.5.1 version of Grafana (earlier versions of Grafana only include an alpha version of the MySQL data source). There is a "Show Help" button under the query field where all the macros are listed. See below:

enter image description here

The first two macros return from and to in the datetime format, the last two return them as epochs.

0
Vicky On

Generated Query, Doesn't fit inside the grafana time range. So you can simply change the time range.

Query From and To Fit inside the time range of the query.

enter image description here

I have added the time range of 100y (100 years) it fit's into my query. so you can adjust your time range accordingly,

enter image description here