0

I'm trying to deal with a particular problem concerning VictoriaMetrics queries lastly and still haven't found the answer how to resolve it, so I've decided to ask here. I have a lot of data to process (range is [30d]), but some samples are incorrect and I want to get rid of them. The query is being executed by the API GET request.

The example below:

.../prometheus/api/v1/query?query=rollup(temperature{label="value"}[30d])/10&step=<step>

And the returned values are:

{
    "status": "success",
    "data": {
        "resultType": "vector",
        "result": [
            {
                "metric": {
                    <labels>,
                    "rollup": "avg"
                },
                "value": [
                    1683180579,
                    "21.13097124571147"
                ]
            },
            {
                "metric": {
                    <labels>,
                    "rollup": "max"
                },
                "value": [
                    1683180579,
                    "22.5"
                ]
            },
            {
                "metric": {
                    <labels>,
                    "rollup": "min"
                },
                "value": [
                    1683180579,
                    "-1.5"
                ]
            }
        ]
    }
}

The problem is that the value "-1.5" as the minimal is incorrect and is a result of a sensor failure which sometimes occur. I want to get rid of this value and calculate minimal/maximal from samples in particular range of values (let's say from "10" to "50"), however I don't want to clamp() that, because it will just return the clamp min/max range instead of real value. I've also tried to wrap it like:

min_over_time(temperature{label="value"}[30d] > 0)/10

However this returns incorrect values as well:

  • for maximum it'd return 21 whereas should return 22.5 (operator < 800)
  • for minimum it'd return 21 whereas should return 20.5 (operator > 0)

I set the cap to "below 800" because as you can notice seeing "/10" in the query - metric gives the temperature with 0.1 decimal precision as integer.

I will be glad for any help and answers to those questions and problems.
Thanks in advance.

markalex
  • 8,623
  • 2
  • 7
  • 32
skylighty
  • 21
  • 3

1 Answers1

0

Can you try the following query instead?

min_over_time(temperature{label="value"}[30d])/10 > 0
hagen1778
  • 669
  • 3
  • 8
  • Yes, I've already tried that. The result is empty. As well with /api/v1/query, as with /api/v1/query_range. – skylighty May 04 '23 at 12:30
  • try the following: > `rollup((temperature{label="value"} > 0 < 50)[30d])` – hagen1778 May 04 '23 at 14:40
  • @skylighty, look at this ^ suggestion. I believe author forgot to tag you. – markalex May 13 '23 at 07:02
  • 1
    Query in your answer will calculate minimum value and them discard it, if it's not positive. More correct way (at least in Prometheus) would be `min_over_time((temperature{label="value"} > 0)[30d:])/10`. I'm not familiar with victoriametrcis and it's `rollup`, but could this query be useful for you, @hagen1778? – markalex May 13 '23 at 07:13
  • tx @markalex! I'm not the one who asked the question. But both approaches, that you and me recommended are based on use of subqueries. In my example, I filter both too low `> 0` and too high `< 50` values. And MetricsQL `rollup` func calculates min/max/avg values for the given selector over specified interval. See https://docs.victoriametrics.com/MetricsQL.html#rollup – hagen1778 May 15 '23 at 07:24
  • @hagen1778, ok. Then suggestion from your comment would be way better than the one from answer. – markalex May 15 '23 at 08:16