Daerst
Daerst

Reputation: 973

Sampling InfluxDB time series data at a specific timestamp with linear interpolation

I have an InfluxDB2 time series database with samples taken roughly every 6 hours, but sometimes additional samples might be in between, or sometimes samples might be missing. I know that the measurement is noise-free and that the underlying measured value is continuous and doesn't change rapidly.

The thing that I'd like to do with this data is to query it at a given point in time, with linear interpolation (and this sounds like one of the most basic operations to me). I do not care whether there is a sample close to it or not, and I don't want to know about explicit samples in a given window. I really only want to treat the data as a piecewise-linear curve, and get the curve's value at a given point in time.

I have looked through the internet, yet haven't found an adequately easy way to do this. Lots of resources seem to use the outdated InfluxQL language, or do some (in my book) overly complicated thing like aggregating windows which I don't think is necessary or even desirable for what I am trying to do.

What's the easiest way to get a linearly-interpolated measurement value at a given timestamp in InfluxDB2? If Influx for some reason is the wrong tool for what I am doing here, I am happy to hear alternatives as well.

Upvotes: 0

Views: 917

Answers (1)

Munin
Munin

Reputation: 1639

I'd like to do with this data is to query it at a given point in time, with linear interpolation.

Suppose you are doing the same query every 30 minute. That means, you want to have data at least for every 30 minute, whether the data was inserted by the data source or interpolated by InfluxDB.

You could try following sample code via Flux language to the fill the missing values:

import "interpolate"

data
    |> interpolate.linear(every: 30m)

See more details here.

Upvotes: 1

Related Questions