I want to make my graphs fit the time range selected, so I use an interval variable and select auto option and set the step count to 1. It works fine when the time range is less than 1 day, but when it comes to be larger than 1 day, I find the variable just stick to be 1d, is that a bug or I am not using it correctly?
Can you provide some more information. Which data source are you using? And can you show your query as well please.
Thank you for your help. My data source is prometheus, and my query is sum(increase(counter[$count_interval])), where $count_interval is set to auto and step count is 1. I have checked in Query Inspector, when the selected time range is less than 1 day, $count_interval gets the right value, but when it is more than 1 day, $count_interval just stick to 1d.
I haven’t seen the auto value for an interval query being used with Prometheus before so this was interesting. It is a very confusing option - definitely something that should be better documented and improved.
There is another way to get an auto interval - the in-built Grafana $__interval
variable:
sum(increase(counter[$__interval]))
So I dug into the details of how the auto option works as it is different from the built in $__interval
variable . The algorithm looks like this (with some rounding down to the nearest minute):
(from - to) / step
now-5m with step 1 = (300 seconds / 1) = 5m
now-5m with step 2 = (300 seconds / 2) = 150s = 2m (with rounding)
Having step set to 1 is strange as I think it means the range vector will always be the time interval.
I have tried about the $__interval variable, but I found that variable can’t do what I want. It doesn’t return the whole time range I selected to show but only a part of it. I’m wondering if I can do some settings to make it return the value of the the whole time range I selected but I don’t know how. Thank you for your help.
Can you show an example - I’m not following.
For example, when the selected time range is last 24 hours and I use $__interval instead of my auto variable, I found the counter value only returns 10% of the correct value.
Can you use the query inspector on the metrics tab and give some examples of when it only returns 10% of the value. This is a commonly used feature so seems strange if it was incorrect.
url:“api/datasources/proxy/1/api/v1/query_range?query=sum(increase(counter%5B30m%5D))&start=1524015086&end=1524101486&step=1800”
My selected time range is last 24 hours, the query inspector shows information above when I’m using the metric “sum(increase(counter[$__interval]))”. I expect that the $__interval should be 1d or 24h, however it seems that it get the value of 30m. That should be why the value returned is not true.
I understand that $interval equals to (from - to) / resolution, but what I want is (from - to). I don’t how I can make it in Grafana
I have done what in https://stackoverflow.com/questions/47141967/how-to-use-the-selected-period-of-time-in-a-query suggests but find it doesn’t work when the selected time range is above 1 day. The variable just sticks to 1d even I select Last 48 hours. Please forget about my comments about the $__interval, I have solved that problem. I have checked the community How to get the time range selected on the dashboard into a variable and find the problem may not be able to be solved, it that still impossible now?
As far as I know, Grafana only supports what’s specified in the docs:
http://docs.grafana.org/reference/templating/#global-built-in-variables
Do we know if there’s been any progress on this front?
I think you want to use built in variable $__range
in increase()
function call.