0

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:

Original Data

Divided by 10

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.

Compare

My current solution is to make separate queries for each name.

Johannes
  • 1
  • 1

1 Answers1

0

Try the following MetricsQL query:

WITH (
    q = {__name__=~"MyMeasurement_[A-Z].*",unit="°C"}
)
(q < 120) or ((q >= 120)/10)
valyala
  • 11,669
  • 1
  • 59
  • 62
  • "q" should be "data"? Then the result is the same as my "WITH" command. – Johannes Jan 23 '23 at 12:49
  • Yes, fixed the typo in the answer. The query should return a line per each measurement on the selected time range. The query should replace values bigger than 120 with values divided by 10 in all the returned lines. – valyala Jan 24 '23 at 07:49
  • This I also expect from the query. But the result is like the image above. Line count is equal to source, but the divided result lines have equal data points (combination of both lines bigger than 120). The lower lines are drawn fine. – Johannes Jan 24 '23 at 10:05
  • I suspect the issue is in the original data - it looks like samples from multiple time series are stored into a single series. Try exporting raw samples and verifying whether they have the expected values. See [how to export raw data from VictoriaMetrics](https://docs.victoriametrics.com/#how-to-export-time-series). See also https://docs.victoriametrics.com/keyConcepts.html – valyala Jan 25 '23 at 08:59
  • Looks like the problem has something to do with empty values in the returned time series. The data where added on change to the data base. So there are not always new values for a series at a spezific time. – Johannes Feb 16 '23 at 16:03