diff --git a/monitoring/metrics.go b/monitoring/metrics.go index dff9b1c..6eb3d95 100644 --- a/monitoring/metrics.go +++ b/monitoring/metrics.go @@ -39,9 +39,6 @@ type SystemMetrics struct { // 路径延迟统计 PathLatencies map[string]float64 `json:"path_latencies"` - // 最近请求 - RecentRequests []RequestLog `json:"recent_requests"` - // 热门引用来源 TopReferers map[string]int64 `json:"top_referers"` @@ -76,7 +73,6 @@ func init() { metrics.StatusCodes = make(map[int]int64) metrics.PathLatencies = make(map[string]float64) metrics.TopReferers = make(map[string]int64) - metrics.RecentRequests = make([]RequestLog, 0, 100) } func CollectMetrics() *SystemMetrics { @@ -103,11 +99,6 @@ func CollectMetrics() *SystemMetrics { func LogRequest(log RequestLog) { metrics.RequestCount.Add(1) - // 使用分段锁减少锁竞争 - bucket := getBucket(log.Path) - bucket.mu.Lock() - defer bucket.mu.Unlock() - mu.Lock() // 添加全局锁保护 map 写入 metrics.StatusCodes[log.StatusCode]++ @@ -130,14 +121,6 @@ func LogRequest(log RequestLog) { } mu.Unlock() - // 保存最近请求记录 - mu.Lock() // 保护 RecentRequests - metrics.RecentRequests = append([]RequestLog{log}, metrics.RecentRequests...) - if len(metrics.RecentRequests) > 100 { - metrics.RecentRequests = metrics.RecentRequests[:100] - } - mu.Unlock() - // 更新平均延迟 count := metrics.RequestCount.Load() if count > 1 { diff --git a/public/index.html b/public/index.html index 26dd0c4..c0b8da2 100644 --- a/public/index.html +++ b/public/index.html @@ -229,28 +229,6 @@ return `${(microseconds/1000000).toFixed(3)}s`; } - // 最近请求 - const recentRequestsHtml = metrics.recent_requests.map(req => ` - - ${new Date(req.time).toLocaleString()} - ${req.path} - ${req.method} - ${req.status_code} - ${formatLatency(req.latency)} - - `).join(''); - - // 热门引用来源 - const topReferersHtml = Object.entries(metrics.top_referers) - .sort(([, a], [, b]) => b - a) - .slice(0, 10) - .map(([referer, count]) => ` -
- ${referer} - ${count} -
- `).join(''); - const metricsHtml = `
@@ -292,30 +270,18 @@
-
-

最近请求

-
- - - - - - - - - - - - ${recentRequestsHtml} - -
时间路径方法状态延迟
-
-
-

热门引用来源

- ${topReferersHtml} + ${Object.entries(metrics.top_referers) + .sort(([, a], [, b]) => b - a) + .slice(0, 10) + .map(([referer, count]) => ` +
+ ${referer} + ${count} +
+ `).join('')}