Skip to content

Commit 5047e9c

Browse files
committed
In the monitoring UI, limit the query types to the top 10
1 parent 58981c1 commit 5047e9c

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

dnscrypt-proxy/monitoring_ui.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)