How transform bytes to GB in the output table?


I’m trying to dsiplay the daily input and output of my Fritzbox in a Grafana Dashboard.

from(bucket: “homeassistant_stage”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“entity_id”] == “fritz_box_7590_ax_b_received”)
|> filter(fn: (r) => r[“_field”] == “value”)
|> filter(fn: (r) => r[“_measurement”] == “B”)
|> aggregateWindow(every: 1d, fn: mean, createEmpty: false)
|> yield(name: “mean”)

I’m getting the correct data in the output table, however I’m struggeling with the conversion part ?

Any help would be much appreciated.

Thanks, Andreas

Welcome Andreas (@1192410 ) to the Influx Community Forum.

Have you seen / tried this? Transform data with mathematic operations in Flux | InfluxDB OSS 2.6 Documentation

Thanks for the link. I’ve seen that, but it gives me an error.

from(bucket: “homeassistant_stage”)

range(start: -10m)
filter(fn: (r) => r._measurement == “B” and r.entity_id == “fritz_box_7590_ax_b_received”)
map(fn: (r) => ({r with _value: r._value / 1073741824}))

Hi @1192410

My guess is that your _value is actually being stored as a string. I think you could use the |> toInt() function and make it work. Can you try this?

from(bucket: "homeassistant_stage")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == "B" and r.entity_id == "fritz_box_7590_ax_b_received")
|> toInt()
|> map(fn: (r) => ({r with _value: r._value / 1073741824}))
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: “mean”)

Thanks @grant1. I have tried it, but still an error.

@1192410 It definitely seems that the _value column is a string (instead of an integer). I read through this post and the conclusion seemed to be to re-populate the data correctly.

The error you received references a column called “data_size”, but I do not see that in your original output:

How are these values getting sent in? Are the commas in _value there, or being added by InfluxDB? I believe InfluxDB is seeing those values as strings.

Can you go to the system where the data is being scraped and sent into Influx and check your settings there?

I just saw that you are using Grafana. Can you try the transformation there, like this?

and if that works, we can convert to GB using a second Grafana transformation.

Not really a great example, but it should look something like this when done:

(for the Operation, change the + to a / )

Thanks, Grafana worked. I did it with the override section. It automatically changed the values from bytes to GB.

1 Like