Ask Your Question
2

How can a Flux Query be written in Influx DB to retrieve only the increasing values?

asked 2021-09-15 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-04-04 11:00:00 +0000

pufferfish gravatar image

To retrieve only the increasing values in InfluxDB using Flux query, you can use the difference() function. The difference() function is used to compute the difference between subsequent non-null records in a column.

Here's an example Flux query that retrieves only the increasing values:

from(bucket: "my-bucket")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "my-measurement")
  |> difference(columns: ["value"])
  |> filter(fn: (r) => r._value > 0.0)

In this query, we first select the relevant data from the my-bucket bucket using the range() function. We then filter the data to only include the my-measurement measurement using the filter() function.

Next, we apply the difference() function to the value column to compute the difference between subsequent non-null records in the column. This effectively calculates the rate of change of the value field.

Finally, we filter out any records where the rate of change is less than or equal to zero, leaving us with only the increasing values.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-09-15 11:00:00 +0000

Seen: 11 times

Last updated: Apr 04 '22