File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -390,13 +390,35 @@ func (mc *MetricsCollector) GetMetrics() map[string]interface{} {
390390 }
391391 }
392392
393- // Get query type distribution
393+ // Get query type distribution sorted by decreasing count and limited to 10
394394 queryTypesList := make ([]map [string ]interface {}, 0 )
395+
396+ // Create a slice of query type-count pairs
397+ type queryTypeCount struct {
398+ qtype string
399+ count uint64
400+ }
401+ queryTypeCounts := make ([]queryTypeCount , 0 , len (mc .queryTypes ))
395402 for qtype , count := range mc .queryTypes {
403+ queryTypeCounts = append (queryTypeCounts , queryTypeCount {qtype , count })
404+ }
405+
406+ // Sort by decreasing count
407+ sort .Slice (queryTypeCounts , func (i , j int ) bool {
408+ return queryTypeCounts [i ].count > queryTypeCounts [j ].count
409+ })
410+
411+ // Take top 10
412+ count := 0
413+ for _ , qtc := range queryTypeCounts {
396414 queryTypesList = append (queryTypesList , map [string ]interface {}{
397- "type" : qtype ,
398- "count" : count ,
415+ "type" : qtc . qtype ,
416+ "count" : qtc . count ,
399417 })
418+ count ++
419+ if count >= 10 {
420+ break
421+ }
400422 }
401423
402424 // Return all metrics
You can’t perform that action at this time.
0 commit comments