influxdbinfluxdb-2flux-influxdb

Influxdb2 flux's today() function using wrong timezone


This is my query:

from(bucket: "power_monitor")
|> range(start: today())
|> aggregateWindow(every: 1h, fn: mean, createEmpty: false)
|> keep(columns: ["_measurement", "_value", "_time"])
|> increase()
|> last()

It tracks the amount of energy used since the start of the day, except I think the timezone is wrong... it was working perfectly until ~8pm when all values were reset to zero.

Can I fix this in the query by adding a time offset? or set my timezone? I think I'd like the values to reset around 2am.

I got this from influx docs and added it to the query, but it doesn't seem to help (still all zeros):

import "timezone"
timezone.fixed(offset: -4h)

Solution

  • You need to set location option, ie.

    import "timezone"
    
    option location = timezone.fixed(offset: -4h) 
    
    from(bucket: "power_monitor")
      ...
    

    Or use location parameter of aggregateWindow function, ie.

    from(bucket: "power_monitor")
      ...
      |> aggregateWindow(every: 1h, fn: mean, createEmpty: false, location: timezone.fixed(offset: -4h))