问题
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
回答1:
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:
The first two macros return from and to in the datetime format, the last two return them as epochs.
回答2:
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.
I have added the time range of 100y (100 years) it fit's into my query. so you can adjust your time range accordingly,
来源:https://stackoverflow.com/questions/46180387/grafana-global-variables-to-access-from-to-values-of-the-time-range