mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 01:40:21 +08:00
fix: 治理 Prometheus 指标基数爆炸和内存缓存无界增长
- 删除高基数标签 key_id/model,移除未使用的指标 concurrency_slots_in_use/streaming_request_duration_seconds - HTTP 客户端池:命名客户端添加 LRU 淘汰上限,tunnel 客户端添加 LRU 淘汰和 last_used_time 追踪 - ResilienceManager:last_errors 改用 deque(maxlen),error_stats/circuit_breakers 添加上限淘汰 - HealthMonitor:_circuit_history 改用 deque(maxlen) - ProviderHealthTracker:清理已无记录的过期 key - PrometheusPlugin:动态指标数量添加上限,超限后拒绝创建 - 中间件使用路由模板替代实际路径,防止动态路径段导致标签爆炸
This commit is contained in:
@@ -439,9 +439,13 @@ class PluginMiddleware:
|
||||
monitor_plugin = self.plugin_manager.get_plugin("monitor")
|
||||
if monitor_plugin and monitor_plugin.enabled:
|
||||
try:
|
||||
# 使用路由模板而非实际路径,避免动态段导致 Prometheus 标签基数爆炸
|
||||
route = request.scope.get("route")
|
||||
endpoint_label = route.path if route and hasattr(route, "path") else "unknown"
|
||||
|
||||
monitor_labels = {
|
||||
"method": request.method,
|
||||
"endpoint": request.url.path,
|
||||
"endpoint": endpoint_label,
|
||||
"status": str(status_code),
|
||||
"status_class": f"{status_code // 100}xx",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user