Custom pivot function in fluxdb

I’m totally new with influxdb2, so I’m not sure how to create a table view and, I’m trying to get just the _time, download, upload, external_ip and pakcetkloss, but I dont know how to get just these fields

here my basic query

from(bucket: “bandwidth”)
|> range(start: -1h)
|> filter(fn: (r) => r["_measurement"] == “Speedtest”)
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: “_value”)

the csv data

_time,download_bandwidth ,upload_bandwidth,interface_externalIp,packetLoss,ping_jitter,ping_latency,upload_bytes,upload_elapsed
5/9/2022 18:00,2341059,4588750,152.231.40.146,0,0.281,1.76,59690904,15002
5/9/2022 18:15,2339711,2376062,152.231.40.146,0,13.5,52.8,21037992,8906
5/9/2022 18:30,2461955,3544365,152.231.40.146,4.03,2.24,48838144,14994
5/9/2022 18:45,3642844,2368945,152.231.40.146,0,1.1,51.5,13443232,5718

another thing I’m trying to get in Mb/s the upload and download.

I found this query, but I can not get download and upload in Mb/s in table view

|> filter(fn: (r) => r["_field"] == “download_bandwidth”)
|> map(fn: (r) => ({r with _value: float(v: r._value) / 131072.0}))

any advise?

not sure if this is what you need? I myself am learning flux

from(bucket: "mbps")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "mbps" and (r["_field"]  == "packetLoss" or r["_field"]  == "upload_bandwidth" or r["_field"]  == "download_bandwidth"))
  |> pivot(rowKey:["_time"], columnKey:["_field"], valueColumn:"_value")
  |> drop(columns:["_value"])  
  |> map(fn: (r) => ({
                     packetLoss: r.packetLoss,
                     upload_bandwidth: r.upload_bandwidth,
                     download_bandwidth: r.download_bandwidth,
                     time: r._time
                   }))

Wou! Is working!!! Thanks!

Another thing what I need… I was trying to convert the download and upload to Mb/s, but I’m not sure how to convert this values using pivots, just can do this in single stats, but using pivots I can do this

filter(fn: (r) => r["_field"] == “download_bandwidth” or r["_field"] == “upload_bandwidth”)

map(fn: (r) => ({r with _value: float(v: r._value) / 131072.0}))

Any advice to get

Saludos,

Maynord A:

trial and error :stuck_out_tongue_winking_eye:

from(bucket: "mbps")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "mbps" 
                   and (r["_field"]  == "packetLoss" 
                   or r["_field"]  == "upload_bandwidth" 
                   or r["_field"]  == "download_bandwidth"))
  |> pivot(rowKey:["_time"], columnKey:["_field"], valueColumn:"_value")
  |> drop(columns:["_value","_start"])    
  |> map(fn: (r) => ({ r with packetLoss: float(v: r.packetLoss)/131072.0, 
  upload_bandwidth: float(v: r.upload_bandwidth)/131072.0, 
  download_bandwidth:float(v: r.download_bandwidth)/131072.0}))
  |> rename(columns: {packetLoss: "Loss", upload_bandwidth: "Upload", download_bandwidth: "Download"})  
  |> keep(columns: ["Loss", "Upload","Download","_time"])

hasta la flux

1 Like

Listo! Mijo! Funciono!! Muchas gracias!

marque solucion p/f?