Hello, I am trying to get a query to return the correct number of minutes (or hours) using stateDuration for a metric collected every 10 minutes. Here is what I have but it returns odd results:
|> range(start: 2023-11-02T21:45:54.088Z, stop:2023-11-09T22:45:54.088Z)
|> filter(fn: (r) =>
r.resourceName == “leak_status”
|> stateDuration(fn: (r) => r._value == 1, unit: 10m)
|> drop(columns: [“_start”, “_stop”])
Any help would be much appreciated.
How are the results weird? It’s hard to me to tell what’s wrong without your expected output and desired output.
@Anaisdg Thank you for the response! Sorry, it definitely would have been helpful to post how the results are showing. So I have a reading that has been in the same state (a value of 1) for a week, and with the stateDuration units set to 10 minutes, I am getting a reading of 2.23 day when I put the time range of last week.
Have you read through this? It sounds like you are trying to do the same thing. Not saying that
stateDuration will not work, but I used
elapsed in the aforementioned thread
This was exactly it! Thank you, I had not found that thread before. Thank you so much!
Great. Please mark above as Solution so others can find.