InfluxDB: Flux - Error: Cannot divide by zero: Unterschied zwischen den Versionen
Aus Wiki-WebPerfect
Admin (Diskussion | Beiträge) |
Admin (Diskussion | Beiträge) |
||
(2 dazwischenliegende Versionen des gleichen Benutzers werden nicht angezeigt) | |||
Zeile 11: | Zeile 11: | ||
*Add following map() function to your query (example you have two fields (field1 & field2)): | *Add following map() function to your query (example you have two fields (field1 & field2)): | ||
<pre> | <pre> | ||
+ | ... | ||
|> map(fn: (r) => ({ r with | |> map(fn: (r) => ({ r with | ||
qos_usage_percent: | qos_usage_percent: | ||
if not exists r.field1 or r.field1 == 0.0 then 0.0 | if not exists r.field1 or r.field1 == 0.0 then 0.0 | ||
− | else if not exists r.field2 or r. | + | else if not exists r.field2 or r.field2 == 0.0 then 0.0 |
− | else r.field1 | + | else r.field1 / r.field2 |
})) | })) | ||
+ | ... | ||
</pre> | </pre> | ||
Zeile 27: | Zeile 29: | ||
− | [[Kategorie: | + | [[Kategorie:TIG-Stack]] |
Aktuelle Version vom 17. Februar 2021, 14:15 Uhr
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