Tweaking the $__interval variable

Hi

Is it possible to define a custom variable which represents the built-in $__interval variable, but the value will not go below a certain threshold (e.g. 15s)?

Background / problem I want to solve (InfluxDB datasource):

Currently I’m using
|> aggregateWindow(every: $__interval, fn: last)
which is needed to avoid the Error “A query returned too many datapoints and the results have been truncated…” when a large time range (e.g. 7 days which will set $__interval to 5m) is selected.

But on the other hand, when I zoom in to e.g. 3 hours (which will set $__interval to 10s), the time series visualization look chopped (unsure why). As long as I go not below 15s the visualization is fine.

Thanks,
Markus

Hi @mez79 and welcome to the Grafana forum.

This seems to work for me:


Notice how I have limited the values, and made sure 15s is not included

In my query:

  |> aggregateWindow(every: ${interval}, fn: mean, createEmpty: false)


vs

1 Like

Hi there and thank you for your suggestion.

Your solution introduces a dropdown where the user can choose between different intervals.
Sure, with this approach I can guarantee that the interval is never below a certain threshold.

But I lose the automatic adjustment of the interval for different time ranges, right?

I was thinking of an approach where I can “calculate” the value of a custom variable based on another variable, e.g. (pseudocode):

Math.max($__interval, 15s)

Do you have any other idea?

@grant2 is correct. But you also need to tweak Auto option options there, where you can customize that auto behaviour:

I use it often - it is visible variable for users. I use default auto value, but user can select own period and that will force aggregation based on current user needs.
Of course there is a risk that user will select options which may kill performance of used TSDB (e.g. 1min aggregation for last 2 days).

2 Likes

Thanks to both of you :pray:. Indeed, this is possible and makes sense.

But now I realized, that Grafana offers a super simple solution for that (no variable definition needed):

Just open the “Query options” section to the right of the InfluxDB datasource and set “Min interval” (for me it was set to 10s, probably I set that some time ago and forgot about it… :grimacing:)