增加API

This commit is contained in:
Alex Yang
2025-11-25 17:07:15 +08:00
parent cd816ae065
commit e21e02a233
14 changed files with 3093 additions and 154774 deletions

View File

@@ -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")