52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
"""
|
|
通用 API 路由(健康检查、版本信息等)
|
|
"""
|
|
from fastapi import APIRouter, Query
|
|
from typing import Optional
|
|
from app.core.response import success_response
|
|
from app.core.config import settings
|
|
from app.utils.monitor import api_monitor
|
|
|
|
router = APIRouter(prefix="/common", tags=["通用"])
|
|
|
|
|
|
@router.get("/health")
|
|
async def health_check():
|
|
"""健康检查"""
|
|
return success_response(
|
|
data={"status": "healthy"},
|
|
message="服务运行正常"
|
|
)
|
|
|
|
|
|
@router.get("/version")
|
|
async def get_version():
|
|
"""获取版本信息"""
|
|
return success_response(
|
|
data={
|
|
"app_name": settings.APP_NAME,
|
|
"version": settings.APP_VERSION,
|
|
},
|
|
message="版本信息"
|
|
)
|
|
|
|
|
|
@router.get("/monitor/stats")
|
|
async def get_monitor_stats(
|
|
endpoint: Optional[str] = Query(None, description="API 端点(不指定则返回所有端点的统计)")
|
|
):
|
|
"""
|
|
获取 API 调用统计信息
|
|
|
|
Args:
|
|
endpoint: API 端点(可选)
|
|
|
|
Returns:
|
|
统计信息
|
|
"""
|
|
stats = api_monitor.get_stats(endpoint)
|
|
return success_response(
|
|
data=stats,
|
|
message="获取统计信息成功"
|
|
)
|