web增加恢复解析统计图表
This commit is contained in:
@@ -51,6 +51,8 @@ func (s *Server) Start() error {
|
||||
mux.HandleFunc("/api/top-resolved", s.handleTopResolvedDomains)
|
||||
mux.HandleFunc("/api/recent-blocked", s.handleRecentBlockedDomains)
|
||||
mux.HandleFunc("/api/hourly-stats", s.handleHourlyStats)
|
||||
mux.HandleFunc("/api/daily-stats", s.handleDailyStats)
|
||||
mux.HandleFunc("/api/monthly-stats", s.handleMonthlyStats)
|
||||
}
|
||||
|
||||
// 静态文件服务(可后续添加前端界面)
|
||||
@@ -191,6 +193,68 @@ func (s *Server) handleHourlyStats(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(result)
|
||||
}
|
||||
|
||||
// handleDailyStats 处理每日统计数据请求
|
||||
func (s *Server) handleDailyStats(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取每日统计数据
|
||||
dailyStats := s.dnsServer.GetDailyStats()
|
||||
|
||||
// 生成过去7天的时间标签
|
||||
labels := make([]string, 7)
|
||||
data := make([]int64, 7)
|
||||
now := time.Now()
|
||||
|
||||
for i := 6; i >= 0; i-- {
|
||||
t := now.AddDate(0, 0, -i)
|
||||
key := t.Format("2006-01-02")
|
||||
labels[6-i] = t.Format("01-02")
|
||||
data[6-i] = dailyStats[key]
|
||||
}
|
||||
|
||||
result := map[string]interface{}{
|
||||
"labels": labels,
|
||||
"data": data,
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(result)
|
||||
}
|
||||
|
||||
// handleMonthlyStats 处理每月统计数据请求
|
||||
func (s *Server) handleMonthlyStats(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取每日统计数据(用于30天视图)
|
||||
dailyStats := s.dnsServer.GetDailyStats()
|
||||
|
||||
// 生成过去30天的时间标签
|
||||
labels := make([]string, 30)
|
||||
data := make([]int64, 30)
|
||||
now := time.Now()
|
||||
|
||||
for i := 29; i >= 0; i-- {
|
||||
t := now.AddDate(0, 0, -i)
|
||||
key := t.Format("2006-01-02")
|
||||
labels[29-i] = t.Format("01-02")
|
||||
data[29-i] = dailyStats[key]
|
||||
}
|
||||
|
||||
result := map[string]interface{}{
|
||||
"labels": labels,
|
||||
"data": data,
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(result)
|
||||
}
|
||||
|
||||
// handleShield 处理屏蔽规则管理请求
|
||||
func (s *Server) handleShield(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
@@ -201,9 +265,9 @@ func (s *Server) handleShield(w http.ResponseWriter, r *http.Request) {
|
||||
// 获取规则统计信息
|
||||
stats := s.shieldManager.GetStats()
|
||||
shieldInfo := map[string]interface{}{
|
||||
"updateInterval": s.globalConfig.Shield.UpdateInterval,
|
||||
"blockMethod": s.globalConfig.Shield.BlockMethod,
|
||||
"blacklistCount": len(s.globalConfig.Shield.Blacklists),
|
||||
"updateInterval": s.globalConfig.Shield.UpdateInterval,
|
||||
"blockMethod": s.globalConfig.Shield.BlockMethod,
|
||||
"blacklistCount": len(s.globalConfig.Shield.Blacklists),
|
||||
"domainRulesCount": stats["domainRules"],
|
||||
"domainExceptionsCount": stats["domainExceptions"],
|
||||
"regexRulesCount": stats["regexRules"],
|
||||
|
||||
Reference in New Issue
Block a user