InfluxQL: getting daily energy consumption (difference) with sparse data and fill(previous)

  Kiến thức lập trình

we are monitoring the power consumption of beamers. They are often plugged off during weekends – in this case, we can not gather any power consumption data. Our typical data looks like this:

We want to visualize the daily consumption in Grafana calculating the daily differences. This query nearly works:

SELECT difference(last("value_number")) 
  FROM "states_history"
  WHERE 
    "dtwin_id" = '57886' 
    AND "state_identifier" = 'stromverbrauch_beamer_gesamt'
    AND $timeFilter 
  GROUP BY time(1d) 
  fill (previous) 

Note: $timefilter is from grafana and inserts the time range selected in the date picker.

This query works perfectly as long as there is at least 1 value per day. But if there is not a single value for the first day of the time range (which often happens on saturdays and sundays when the beamers are plugged off), fill(previous) can not calculate a value and the whole day is not displayed. In the screenshot below, the green bars are for a beamer and monday is missung due to the problem described. The blue bars are for a different measurement with constant data.

This behaviour of fill(previous) is well-known: https://github.com/influxdata/influxdb/issues/6878

Does anyone have a good solution/workaround for this? Maybe, a completely different query could be used? There is some workaround mentioned in the github issue, but only for flux language, not for InfluxQL.

Thanks & regards

  • Searching for solutions
  • read the complete github issue history

New contributor

PhilippR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT