grafana / influxdb-flux-datasource

Grafana datasource plugin for Flux (InfluxDB)
Apache License 2.0
51 stars 21 forks source link

additional range parameters #69

Open errantspark opened 4 years ago

errantspark commented 4 years ago

the $range parameter (as i understand it, i don't fully grok the code) is expanded in datasource.ts to start and stop values, it would be very useful to be able to split this out into two parameters such as $start and $stop as then you could(?) perform math on the start and end positions greatly simplifying and speeding up time-shifted queries

what i'm envisioning is something like

from(bucket: "telegraf/autogen")
  |> range(start:$start-1d, stop:$stop-1d)

to perform a timeshifted query to make it easy to compare from one day to the next

MarcoPignati commented 4 years ago

I have found this workaround. I hope it is helpful.

starttime =  time(v: $__from * 1000000) //transform to ns. 
stoptime  = time(v: $__to * 1000000)

from(bucket: "telegraf/autogen")
  |> range(start: starttime, stop: stoptime)

time() is a flux function to transform a number in ns to RFC3339

gaurav-fk commented 4 years ago

Thanks @MzazM it works. I used it as follows for comparing data in a given time range to timeshifted data 1hr back in Grafana.

starttime =  time(v: ($__from - (1* 3600 * 1000)) * 1000000) 
stoptime  = time(v: ($__to - (1 * 3600 * 1000)) * 1000000)