autoInterval support in v2

I use InfluxDB v2 alpha 8 to visualize some sensor data. The sensors update about once per minute. I have noticed that when I select a large time window (e.g. 2 weeks), a large amount of data is transmitted, which is slow and unnecessary.

Therefore I thought it would be useful to have the graphs automatically show the mean of the data, using a variable time window based on the selected duration.

I have seen How To: Building Flux Queries in Chronograf which uses every: autoInterval which seems to do exactly what I want. When I try to use it like:

from(bucket: “home”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r.topic == “sensor/living/light”)
|> aggregateWindow(fn: mean, every: autoInterval)

I get the error

failed to compile query: type error 6:39-6:51: undefined identifier “autoInterval”

I also tried to manually calculate a window, but I am not sure what the syntax should look like. e.g. something like

from(bucket: “home”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r.topic == “sensor/living/light”)
|> aggregateWindow(fn: mean, every: (v.timeRangeStop - v.timeRangeStart) / 100)

Is that possible? Thanks!

@bschwehn In v2, the variable has been renamed to v.windowPeriod.

This should give you what you want:

from(bucket: "home")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r.topic == "sensor/living/light")
  |> aggregateWindow(fn: mean, every: v.windowPeriod)

Thanks @scott.

The query works, but I don’t think this quite does what I want

Using the every: parameter along with autoInterval allows Chronograf to dynamically determine the size of the window based on the screen real-estate that is available for visualizing the results.

Whereas

The value of this variable is calculated by dividing the total time within the displayed time range by the dashboard refresh interval (defined by the Refresh dropdown).

What I was hoping for is a way to automatically average/sample the data based on the screen estate.

E.g. if the query is used to display a graph in a small widget 200px wide, no matter how large the time window selected is, I only want 200 datapoints transfered. Any more is not very useful, because we are limited to 200px anyway, so there is no point in first sending 10k data points to the browser, then esentially reducing them to 200 clientside during rendering.

With the query you provided, still 5mb of data is transfered for a single sensor widget with a 2wk timeframe, which is excessive and very slow when on a slow connection.

Anyway, I have created a task that aggregates by hour and can use this instead, if the selected timewindow is large, but was wondering if there is something built in.
On the other hand, the advantage of scheduling the aggregates is (I guess) that it will also lower the DB server load, as aggregation is then only done once, not on every graph display.

Thanks
Ben