完善权限缓存与监控指标
This commit is contained in:
@@ -8,7 +8,7 @@ from typing import Annotated
|
||||
from fastapi import APIRouter, Depends, status
|
||||
|
||||
from app.core.deps import get_current_user
|
||||
from app.core.permission_monitor import get_permission_monitor
|
||||
from app.core.permission_monitor import evaluate_permission_system_health, get_permission_monitor
|
||||
|
||||
router = APIRouter(prefix="/permission-monitoring", tags=["permission-monitoring"])
|
||||
|
||||
@@ -98,37 +98,4 @@ async def permission_system_health(
|
||||
metrics = monitor.get_metrics()
|
||||
cache_stats = monitor.get_cache_stats()
|
||||
|
||||
# 计算健康分数
|
||||
check_metrics = metrics["check_metrics"]
|
||||
cache_metrics = metrics["cache_metrics"]
|
||||
|
||||
health_score = 100
|
||||
issues = []
|
||||
|
||||
# 检查错误率
|
||||
if check_metrics["error_rate"] > 1:
|
||||
health_score -= 20
|
||||
issues.append("权限检查错误率过高")
|
||||
|
||||
# 检查缓存命中率
|
||||
if cache_metrics["hit_rate"] < 50:
|
||||
health_score -= 10
|
||||
issues.append("缓存命中率过低")
|
||||
|
||||
# 检查平均响应时间
|
||||
if check_metrics["avg_time"] > 0.01: # 10ms
|
||||
health_score -= 10
|
||||
issues.append("权限检查响应时间过长")
|
||||
|
||||
# 检查拒绝率
|
||||
if check_metrics["deny_rate"] > 50:
|
||||
health_score -= 5
|
||||
issues.append("权限拒绝率过高")
|
||||
|
||||
return {
|
||||
"status": "healthy" if health_score >= 80 else "degraded" if health_score >= 50 else "unhealthy",
|
||||
"health_score": max(0, health_score),
|
||||
"issues": issues,
|
||||
"metrics": metrics,
|
||||
"cache_stats": cache_stats,
|
||||
}
|
||||
return evaluate_permission_system_health(metrics, cache_stats)
|
||||
|
||||
Reference in New Issue
Block a user