Set variable based on dashboard timespan in JSON datasources

Using Grafana version 10.1.2 with JSON API and Infinity datasources

Is there a way to set a variable based on the time span chosen in the dashboard?

I need to define the data resolution in my URL
http://myhost.org/api/measurement/param={hourly,daily,monthly,yearly}

I’ve looked at the $__range and $__interval variables, but they don’t work in any of the JSON datasource plugins. Is there another option?

I’d like to do something like:
if $__range < 7d:
${param} = ‘hourly’
elif $__range >= 7d and $__range < 30d:
${param} = ‘daily’

I’m currently letting the user select Hourly/Daily/Monthly/Yearly from a variable dropdown. But if the user selects Monthly and then chooses a one week timespan, they get no data. Likewise, if they choose Hourly and then define a 3 year timespan, the API will reject the request. I would to adjust this automatically.

Thanks

welcome @jasondec

You might want to look at UQL with infinity and jsonata where you have more control on these type of things.

Thanks @yosiasz.
I just came across Macros in the Infinity documentation which may be just the thing I’m looking for.

1 Like

The $__customInterval() macro from Infinity was exactly what I needed.