Sorting tables from influx DB 2.x

Hi, I am using a bar guage panel fed from an influxDB 2.x query to display disk usage from n number of servers with x number of devices. It works as expected, but I cant get the resultant tables sorted.
e.g. query is
from(bucket: “telegraf”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “disk”)
|> filter(fn: (r) => r[“fstype”] == “NTFS” or r[“fstype”] == “msdosfs”)
|> filter(fn: (r) => r[“_field”] == “used_percent”)
|> mean(column: “_value”)

and it displays fine. However, its sorted by the field device, and I would like it displayed by host. There does not seem to be a place to sort the tables by tags.
if I group and ungroup it, it displays in influxDB’s query builder how I want it to.e.g

from(bucket: “telegraf”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “disk”)
|> filter(fn: (r) => r[“fstype”] == “NTFS” or r[“fstype”] == “msdosfs”)
|> filter(fn: (r) => r[“_field”] == “used_percent”)
|> mean(column: “_value”)
|> group()
|> sort(columns: [“host”,“device”])
|> group(columns: [“host”])
|> yield(name: “mean”)

but grafana gets totally confused and does not render it. Here is an example. Normally the hostnames would be displayed, but for the purposes of this host I updated the field override to be hhost instead of host. But the sorting order is by device name, not host which I want

OK, I sort of figured it out. If I create a new column, and group on it, it “naturally” sorts by that group key it seems

|> map(fn: (r) => ({r with hostdevice: (r.host+" "+r.device)}))
|> group(columns: [“hostdevice”])
|> mean(column: “_value”)
|> yield(name: “mean”)

1 Like