InfluxDB: Flux - Error: Cannot divide by zero

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche

Error

Cannot divide by zero


Cause

This error occurs because your data/metric points have different types.
Mostly the fault is that your data contains "0" and the datatype of "0" = "Integer". But the other datatypes are "Float" and that's the reason you can't calculate.


Solution

  • Add following map() function to your query (example you have two fields (field1 & field2)):
...
  |> map(fn: (r) => ({ r with
      qos_usage_percent:
        if not exists r.field1 or r.field1 == 0.0 then 0.0
        else if not exists r.field2 or r.field2 == 0.0 then 0.0
        else r.field1 / r.field2
  }))
...


More information's: https://community.influxdata.com/t/flux-how-to-handle-division-by-zero/16704