Network interfaces graph (Min/Max/Average)

Hello,

Can someone help me here?

I have this query:

from(bucket: "nms")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "device14")
  |> filter(fn: (r) => r["user"] == "interfaceXYZ")
  |> filter(fn: (r) => r["_field"] == "traffic_in" or r["_field"] == "traffic_out")
  |> map(fn: (r) => ({
      r with
      _value: r._value * 8
    })
  )
  |> derivative(unit: 1s, nonNegative: true)
  |> yield(name: "nonnegative derivative")

This query returns the Upload/Download traffic in bytes of a given interface.

Is there a way to get the Average traffic usage from the Upload/Download using the current data?
I would like to have traffic_average_in and traffic_average_out, if possible.

Thank you.

Hi @Diorges_Rocha,
Welcome to the community! So yes perhaps something along the lines of this:

traffic = from(bucket: "nms")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "device14")
  |> filter(fn: (r) => r["user"] == "interfaceXYZ")
  |> filter(fn: (r) => r["_field"] == "traffic_in" or r["_field"] == "traffic_out")
  |> map(fn: (r) => ({
      r with
      _value: r._value * 8
    })
  )
  |> derivative(unit: 1s, nonNegative: true)
  |> group(columns: ["_field"], mode:"by")


  traffic |> mean() |> yield(name: "average_In_Out")

You can also use an aggregate window with mean instead of directly mean()