0

I can't for the life of it figure out how to get the length or duration of a series within a given time frame in InfluxDB 1.8.

I need this to calculate kWh from a kW reading, but I would have thought lots of people would need this to e.g. calculate server uptime.

If nothing else works, I could work with getting the time between first and last point of a series, but really would like to be able to exclude any gaps in between.

I feel elapsed() may be used for that, but as the documentation says it seems to only give nonsensical results if combined with a GROUP BY time clause.

Any help would be greatly appreciated.

Jan Garaj
  • 25,598
  • 3
  • 38
  • 59
maqs
  • 3
  • 2
  • I would like to know how can you calculate KWh from KW reading, when you know duration of the series? I see logical problem with this approach. E.g. what is the gap when you want to exclude them. Timeseries have gaps in their design, they are not continuous. I would recommend https://community.grafana.com/search?q=influxdb%20energy%20kwh That's IMHO FAQ from users with wattmeter values in InfluxDB. – Jan Garaj Feb 13 '21 at 09:26
  • Thanks @JanGaraj - the idea was to work with the average wattage over the uptime of source - so when that is e.g. 15kW over 2.5h, it would have generated 37.5kWh on that day. That is generally good enough an approximation - and with that particular inverter unfortunately I don't have a monotonically increasing kWh reading. The reason I need to subtract gaps is that the source may not be on continuously during the day. The entries under your link you shared all seem to proceeded from some Wh or Watt-second reading - or am I maybe missing something? – maqs Feb 14 '21 at 00:05
  • Yes, you need `integral` + some math https://community.grafana.com/t/how-do-you-measure-the-area-under-a-line-graph/15386 And if the "gap" is zero value, then gaps won't be problem, otherwise you may need data normalization before integral. – Jan Garaj Feb 14 '21 at 01:12
  • Thanks for the pointer, @JanGaraj - had completely missed the existence of *integral* so far. But so far I am completely failing to get any valid and consistent results with it, even with a *math* divisor of the right size. Biggest complexifier do seem to be the gaps, even though they are indeed zero value. In the Grafana forum you once mentioned the need for second aggregation with *sum* - do you know of an actual sample query that transforms kW or W into *kWh per day* this way? – maqs Feb 14 '21 at 22:29
  • Gaps are not a problem, because integral of zero is zero. If you need correct answer, then you need to ask correctly first: https://stackoverflow.com/help/minimal-reproducible-example I gave you direction, but not answer because I don't know your data. There very likely must be data "normalization" before integral based on sampling frequency. – Jan Garaj Feb 15 '21 at 03:50
  • @JanGaraj - point taken, though in this case I don't think a reproducible example would have helped much further. I believe the almost insurmountable issue lies in the tension between having to do *"GROUP BY time(24h)"* for a daily aggregate, and also needing that function for "data normalization". You would think the integration of gaps and zero values would be unproblematic, but it's giving these weird artifacts once you start time aggregation. Think I will need solve this upstream by generating incremental kwh fractions based on the actual sample interval. Many thanks for your help anyway!! – maqs Feb 15 '21 at 11:21

0 Answers0