Influxdb Query to Json

Hi All,

Hope you can help me with this issue. I’m using InfluxDb as Datasource in Grafana. Recently I added a plugin: https://globalnoc.github.io/globalnoc-worldview-panel/docs/Data%20Settings/map-data to show Network circuits utilization.

The problem I am facing is I need a JSON in the following format:
´´´
[
{
“name”: “hostname.a.b.c+interfaceET-12+input”,
“datapoints”: [[1856397.26666666, 1633959000], [1650972.84444445, 1633958640], [1373735.42222222, 1633958280],…]
},
{
“name”: “hostname.a.b.c+interfaceGE-42+input”,
“datapoints”: [[1856397.26666666, 1633959000], [1650972.84444445, 1633958640], [1373735.42222222, 1633958280],…]
},
{
“name”: “hostname.a.b.c+interfaceET-12+output”,
“datapoints”: [[19015224.4666666, 1633959000], [16855873.2777778, 1633958640], [15234882.4222223, 1633958280],…]
},
{
“name”: “hostname.d.e.f+interfaceET-45+input”,
“datapoints”: [[986576809.333332, 1633959000], [913103824.399999, 1633958640], [890706239.466668, 1633958280],…]
},

]
´´´
This is the query I am running:
from(bucket: “librenms”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“hostname”] == “10.10.40.10”)
|> filter(fn: (r) => r[“ifName”] == “xe-0/2/0”)
|> filter(fn: (r) => r[“_field”] == “ifInBits_rate” or r[“_field”] == “ifOutOctets_rate”)
|> map(fn: (r) => ({
r with _field:
if r._field == “ifInBits_rate” then “In Bits”
else “Out Bits”
})
)
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: “mean”)

I tried to format as json but is not the same
import “json”
from(bucket: “librenms”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“hostname”] == “10.10.40.10”)
|> filter(fn: (r) => r[“ifName”] == “xe-0/2/0”)
|> filter(fn: (r) => r[“_field”] == “ifInBits_rate”)
|> map(fn: (r) => ({r with jsonStr: string(v: json.encode(v: {“name”: “test_input”, “datapoints”: r._value}))}))

Do you think is feasable?

Thanks