Equivalent SLIMIT for flux query

Hello,

I search the equivalent of SLIMIT(influxQL query) for FLUX query please?

I would like for example, to display only the top 5 from tag filter.

Many thanks for help,

Hi @indi
Did you see/try this? top() function | Flux 0.x Documentation

Hi @grant1

thanks for you help.
I tried this, but i gor an error: invalid: error @8:6-8:15: expected stream[A] but found string (argument tables)

from(bucket: v.bucket)
|> range(start: v.timeRangeStart, stop:v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “HDD” and r._field == “HDD_Read_IOPS”
top(n: 3)
)

Sorry, i’m a begginer with influxdb 2 /FLUX query… :confused:

Hi @indi

Can you try this…

from(bucket: v.bucket)
|> range(start: v.timeRangeStart, stop:v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “HDD” and r._field == “HDD_Read_IOPS”)
|> top(n: 5)
|> yield(name: "top_5")

Hi @grant1,

Thank you for your help.

Sorry but it don’t work.
i got all HDD in the list instead of the 5 highest

in fact, i search to convert an influxql query to flux query:

SELECT mean(“HDD_Read_IOPS”) FROM “HDD”
WHERE (“server” =~ /^$SRV$/) AND $timeFilter
GROUP BY time($__interval), “hdd_id” SLIMIT 10

Can you show a screenshot of the list so I can see the column names?

Hi @grant1,
Please find the csv imported
With many srv"x", hdd"x"

#datatype measurement,tag,tag,double,double,double,dateTime:number
HDD,server,hdd_id,HDD_Read_IOPS,HDD_Write_IOPS,HDD_Read_ms,time
HDD,srv1,hdd1,35,33,1,1671233940
HDD,srv1,hdd1,24,69,1,1671234000
HDD,srv1,hdd1,97,57,2,1671234060
HDD,srv1,hdd1,30,78,2,1671234120
HDD,srv1,hdd1,53,83,2,1671234180
HDD,srv1,hdd1,56,85,2,1671234240
HDD,srv1,hdd1,32,25,22,1671234300
HDD,srv1,hdd1,29,89,6,1671234360
HDD,srv1,hdd1,33,41,1,1671234420
HDD,srv1,hdd1,22,15,8,1671234480
HDD,srv1,hdd1,24,95,4,1671234540
…
HDD,srv1,hdd2,35,33,1,1671233940
HDD,srv1,hdd2,24,69,1,1671234000
HDD,srv1,hdd2,97,57,2,1671234060
HDD,srv1,hdd2,30,78,2,1671234120
HDD,srv1,hdd2,53,83,2,1671234180
HDD,srv1,hdd2,56,85,2,1671234240
HDD,srv1,hdd2,32,25,22,1671234300
HDD,srv1,hdd2,29,89,6,1671234360
HDD,srv1,hdd2,33,41,1,1671234420
HDD,srv1,hdd2,22,15,8,1671234480
HDD,srv1,hdd2,24,95,4,1671234540
…
HDD,srv1,hdd3,35,33,1,1671233940
HDD,srv1,hdd3,24,69,1,1671234000
HDD,srv1,hdd3,97,57,2,1671234060
HDD,srv1,hdd3,30,78,2,1671234120
HDD,srv1,hdd3,53,83,2,1671234180
HDD,srv1,hdd3,56,85,2,1671234240
HDD,srv1,hdd3,32,25,22,1671234300
HDD,srv1,hdd3,29,89,6,1671234360
HDD,srv1,hdd3,33,41,1,1671234420
HDD,srv1,hdd3,22,15,8,1671234480
HDD,srv1,hdd3,24,95,4,1671234540
…

Many thanks,

can you clarify your statement above, in terms of which data points you would like to display?

for example, this?

HDD,srv1,hdd1,97,57,2,1671234060
HDD,srv1,hdd2,97,57,2,1671234060
HDD,srv1,hdd3,97,57,2,1671234060
HDD,srv1,hdd4,97,57,2,1671234060
HDD,srv1,hdd5,97,57,2,1671234060

Hi grant1,

for example , I searched a way to get the top 2 Read IOPS of theses two hdd in bolt display in grafana.

#HDD,server,hdd_id,HDD_Read_IOPS,HDD_Write_IOPS,HDD_Read_ms,time
> HDD,srv1,hdd1,5197,557,2,1671234060
> HDD,srv1,hdd2,5297,51,2,1671234060
HDD,srv1,hdd3,12,456,2,1671234060
HDD,srv1,hdd4,56,11,2,1671234060
HDD,srv1,hdd5,98,236,2,1671234060

I got only two point in grafana, instead of a full line (graph)
i tried with this query (not fully optimal/necessary about substring :slight_smile: ) but this is the closest result I have found

import “strings”

from(bucket: v.bucket)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “HDD”)
|> drop(columns: [“server”])
|> filter(fn: (r) => r._field == “HDD_Read_IOPS”)
|> map(fn: (r) => ({r with newhddid: strings.substring(v: r.hdd_id, start: 0, end: 4)}))
|> group(columns: [“newhddid”])
|> highestMax(n: 2, groupColumns: [“newhddid”])
|> aggregateWindow(column: “_value”, every: v.windowPeriod, fn: mean)

maybe withpivot function?
i continue to search…

thanks for your help in any case