add FastApi实时性能监控

This commit is contained in:
jxxghp
2025-08-01 17:47:55 +08:00
parent 8ab233baef
commit 1dd3af44b5
10 changed files with 857 additions and 21 deletions
+16 -15
View File
@@ -1,23 +1,24 @@
from .token import *
from .user import *
from .response import *
from .site import *
from .subscribe import *
from .context import *
from .servarr import *
from .servcookie import *
from .plugin import *
from .history import *
from .dashboard import *
from .download import *
from .event import *
from .exception import *
from .file import *
from .history import *
from .mediaserver import *
from .message import *
from .tmdb import *
from .transfer import *
from .monitoring import *
from .plugin import *
from .response import *
from .rule import *
from .servarr import *
from .servcookie import *
from .site import *
from .subscribe import *
from .system import *
from .file import *
from .exception import *
from .system import *
from .event import *
from .tmdb import *
from .token import *
from .transfer import *
from .user import *
from .workflow import *
from .download import *
+2 -1
View File
@@ -3,7 +3,8 @@ from typing import Optional, Dict, Any, List, Set, Callable
from pydantic import BaseModel, Field, root_validator
from app.schemas import MessageChannel, FileItem
from app.schemas.message import MessageChannel
from app.schemas.file import FileItem
class Event(BaseModel):
+76
View File
@@ -0,0 +1,76 @@
from datetime import datetime
from typing import List
from pydantic import BaseModel
class RequestMetrics(BaseModel):
"""
请求指标模型
"""
path: str
method: str
status_code: int
response_time: float
timestamp: datetime
client_ip: str
user_agent: str
class PerformanceSnapshot(BaseModel):
"""
性能快照模型
"""
timestamp: datetime
cpu_usage: float
memory_usage: float
active_requests: int
request_rate: float
avg_response_time: float
error_rate: float
slow_requests: int
class EndpointStats(BaseModel):
"""
端点统计模型
"""
endpoint: str
count: int
total_time: float
errors: int
avg_time: float
class ErrorRequest(BaseModel):
"""
错误请求模型
"""
timestamp: str
method: str
path: str
status_code: int
response_time: float
client_ip: str
class MonitoringOverview(BaseModel):
"""
监控概览模型
"""
performance: PerformanceSnapshot
top_endpoints: List[EndpointStats]
recent_errors: List[ErrorRequest]
alerts: List[str]
class MonitoringConfig(BaseModel):
"""
监控配置模型
"""
slow_request_threshold: float = 1.0
error_threshold: float = 0.05
cpu_threshold: float = 80.0
memory_threshold: float = 80.0
max_history: int = 1000
window_size: int = 60