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

心不动则不痛 提交于 2020-01-13 20:27:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!