Cut incorrent, unwanted values from the function calculation base in VictoriaMetrics/Prometheus

92 Views Asked by At

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.

1

There are 1 best solutions below

6
On

Can you try the following query instead?

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