I'm trying to divide the value by 10, if the value is inside an defined range.
Source is VictoriaMetrics and Grafana with Prometheus plugin is used to query the data.
I tested this code but either get an error message or the values to be divided end up as one curve instead of two.
MetricsQL
WITH (
data = {__name__=~"MyMeasurement_[A-Z].*",unit="°C"} > 0 < 120,
data1 = {__name__=~"MyMeasurement_[A-Z].*",unit="°C"} > 120 < 1000
)
(data or (data1/10))
({__name__=~"MyMeasurement_[A-Z].*",unit="°C"} if ({__name__=~"MyMeasurement_[A-Z].*",unit="°C"} < 120)) default ({__name__=~"MyMeasurement_[A-Z].*",unit="°C"})`
With Influx this code works fine:
|> map(fn: (r) => ({
r with _value:
if r._value >= ${tempSplitLimit} and r._value < 1000 then float(v:r._value) / 10.0
else float(v:r._value)
}))
Image:
Update:
The problem seems to be, that the data not added at the same time.
So VictoriaMetrics return a table with some undefined entry.
The or operator fill the empty fields with data from another signal.
My current solution is to make separate queries for each name.
Try the following MetricsQL query: