Flux - top from all tables?

Hello.

The question arose - how to get the top records among all tables after grouping?

Query:

mean = from(bucket: “db/rp”)
|> range($range)
|> filter(fn:(r) => r._measurement == “procstat”
and r._field == “memory_usage”
and r.host == “host.local”)
|> group(columns: [“process_name”, “pid”], mode:“by”)
|> mean()
|> top(n:10)

This query returns a result, where each group is a separate table and the top() function is tried on each table separately:

#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,string,string,double
#group,false,false,true,true,true,true,false
#default,_result,
,result,table,_start,_stop,process_name,pid,_value
,0,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,NetworkManager,1114,0.010059831663966179
,1,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,agetty,1531,0.0012521602911874652
,2,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,agetty,1537,0.0012400033883750439
,3,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,alertmanager,3980,0.042676784098148346
,4,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,ata_sff,520,0
,5,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,auditd,1005,0.0016229456523433328
,6,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,automount,1555,0.0047958954237401485
,7,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,bash,29107,0.0033431462943553925
,8,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,bash,32029,0.0013615723000839353
,9,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,bioset,562,0
,10,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,bioset,93,0
,11,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,bioset,94,0
,12,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,bioset,95,0
,13,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,bioset,969,0
,14,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,chronyd,1048,0.0022064766380935907
,15,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,controller,5259,0.0066923713311553
,16,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,crond,1529,0.002607654081657529

How do I get the top among all the tables?
Something like this:

#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,string,string,double
#group,false,false,true,true,true,true,false
#default,_result,
,result,table,_start,_stop,process_name,pid,_value
,0,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,NetworkManager,9999
,0,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,agetty,8888
,0,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,agetty,7777
,0,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,alertmanager,6666
,0,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,ata_sff,5555
,0,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,auditd,4444
,0,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,automount,3333
,0,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,bash,2222
,0,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,bash,1111
,0,2020-07-15T07:02:51.498773511Z,2020-07-15T08:02:51.498773511Z,bioset,111

Case - get the top processes for memory usage for the period.

Hi. You can use group() again after the mean.

mean = from(bucket: “db/rp”)
|> range($range)
|> filter(fn:® => r._measurement == “procstat”
and r._field == “memory_usage”
and r.host == “host.local”)
|> group(columns: [“process_name”, “pid”], mode:“by”)
|> mean()
|> group()
|> top(n:10)

This will give you the top 10 of all of the series.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.