Help with legend ordering and trending data

I’ve recently switched over to InfluxDB using Flux QL and for the most part I’ve managed to get some nice looking dashboards in Grafana v10.0.0 (they aren’t too fancy) which is nice but I’m after a couple of tips (if possible). One of the queries I’m running is below.

from(bucket: "influx_bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "Cisco-IOS-XE-interfaces-oper:interfaces/interface")
  |> filter(fn: (r) => r["_field"] == "statistics/rx_kbps" or r["_field"] == "statistics/tx_kbps")
  |> filter(fn: (r) => r["diffserv_info/diffserv_target_classifier_stats/classifier_entry_name"] != "class-default")
  |> filter(fn: (r) => r["source"] == "switch-name")
  |> filter(fn: (r) => r["host"] == "telegraf-server")
  |> filter(fn: (r) => r["name"] == "switch-interface")
  |> map(fn: (r) => ({r with _value: r._value * 1000 }))
  |> map(fn: (r) =>  ({
        r with subscription:
          if r._field == "statistics/rx_kbps" then "Inbound Traffic"
          else if r._field == "statistics/tx_kbps" then "Outbound Traffic"
          else "fail"
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)

I would like to be able to do two things:

  1. Control the legend order (either based on the order of my _fields or by some kind of group mapping table); and
  2. Be able to create a trend line over some kind of period interval time range period so that I can start doing historic trending of my data. The use case here is that I can look at data over a period of 30days to see the actual metrics and then see a nice trend line of that data over the same time (or maybe there is a much better way to do it).

I looked around but my google-foo wasn’t working

Hi @Brad

Re: your question #2 about trend lines, have you considered these?

moving average
timed moving average
exponential moving average

and probably less useful:

Thanks Grant, I gave the timed moving average a try and I think that’s what I’m after. Not sure if I’m doing it correctly but I essentially just replaced the line which had aggregateWindow with the following:

|> timedMovingAverage(every: 7d, period: 90d)

If I am reading it correctly, it uses the drop-down time range to collect enough data and then collects the average over 90 days and plots the data in increments of every 7 days. Is that a fair assumption?

Hi @Brad

Unfortunately I have not used that function. Whatever the help file says is all I know.