增加API
This commit is contained in:
@@ -87,10 +87,27 @@ func (s *Server) handleStats(w http.ResponseWriter, r *http.Request) {
|
||||
dnsStats := s.dnsServer.GetStats()
|
||||
shieldStats := s.shieldManager.GetStats()
|
||||
|
||||
// 获取最常用查询类型
|
||||
topQueryType := "A"
|
||||
maxCount := int64(0)
|
||||
for queryType, count := range dnsStats.QueryTypes {
|
||||
if count > maxCount {
|
||||
maxCount = count
|
||||
topQueryType = queryType
|
||||
}
|
||||
}
|
||||
|
||||
// 获取活跃来源IP数量
|
||||
activeIPCount := len(dnsStats.SourceIPs)
|
||||
|
||||
stats := map[string]interface{}{
|
||||
"dns": dnsStats,
|
||||
"shield": shieldStats,
|
||||
"time": time.Now(),
|
||||
"dns": dnsStats,
|
||||
"shield": shieldStats,
|
||||
"topQueryType": topQueryType,
|
||||
"activeIPs": activeIPCount,
|
||||
"avgResponseTime": dnsStats.AvgResponseTime,
|
||||
"cpuUsage": dnsStats.CpuUsage,
|
||||
"time": time.Now(),
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
Reference in New Issue
Block a user