grafanaflux

Grafana is not showing average value


I'm trying to get an average value from the data I've read. The bottom graph shows the data I have received so far, and the number on top should represent the average value, but at first glance, it is clear that it is not the average.

Graphs

This is the query I have tried:

 from(bucket: "DP")
  |> range(start: -1d)
  |> filter(fn: (r) => r._field == "forward_energy")
  |> window(every: 1d)
  |> mean()

Solution

  • Using range(start: -1d) and window(every: 1d) youl will still get more than one datapoint. Windowing by day will use midnight (UTC if you have not set the location option) as the boundry.

    If now is 2023-04-11T08:00:00Z for example the range will get data from 2023-04-10T08:00:00Z to 2023-04-11T08:00:00Z, then the window will create two time-buckets: one from 2023-04-10T08:00:00Z to 2023-04-11T00:00:00Z and the pther from 2023-04-11T00:00:00Z to 2023-04-11T08:00:00Z.

    The mean function will then extract the mean value for each window and you will get a single series with two datapoints: one at 2023-04-10T08:00:00Z and the other at 2023-04-11T00:00:00Z.

    Grafana than is only showing a single point (probably the first one).

    If you only care about the mean in the last day (24h) than you can skip the window function:

    from(bucket: "DP")
      |> range(start: -1d)
      |> filter(fn: (r) => r._field == "forward_energy")
      |> mean()