Hello,
I have this query working in overwriting my original hrStorageUsed and hrStorageSize fields with disk allocation units by using map function:
from(bucket: “db-snmp-synology”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “hrStorageTable”)
|> filter(fn: (r) => r[“_field”] == “hrStorageUsed” or r[“_field”] == “hrStorageSize”)
|> filter(fn: (r) => r[“hrStorageIndex”] == “53”)
|> group()
|> pivot(rowKey: [“_time”], columnKey: [“_field”], valueColumn: “_value”)
|> map(fn: (r) => ({r with hrStorageSize: r.hrStorageSize * 4096}))
|> map(fn: (r) => ({r with hrStorageUsed: r.hrStorageUsed * 4096}))
|> drop(columns: [“_start”, “_stop”])
How could I calculate the used percentage from the above query?
if I use:
|> map(fn: (r) => ({r with percent_used: r.hrStorageUsed / r.hrStorageSize * 100}))
would return 0 and would probably be some kind of integer overflow.
if I go with float, it won’t work either:
|> map(fn: (r) => ({r with percent_used: float(v: r.hrStorageUsed / r.hrStorageSize * 100)}))
Screenshot:
How could I make this work?