32 lines
843 B
Python
32 lines
843 B
Python
"""
|
||||
|
|
健康检查 API
|
|||
|
|
============
|
|||
|
|
|
|||
|
|
【功能说明】全链路健康探活接口。
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
from __future__ import annotations
|
|||
|
|
|
|||
|
|
import logging
|
|||
|
|
|
|||
|
|
from fastapi import APIRouter
|
|||
|
|
|
|||
|
|
from app.schemas.project import ApiResponse
|
|||
|
|
from app.services.health_service import check_all
|
|||
|
|
|
|||
|
|
logger = logging.getLogger("agent.health.api")
|
|||
|
|
|
|||
|
|
router = APIRouter(prefix="/api/health", tags=["健康检查"])
|
|||
|
|
|
|||
|
|
|
|||
|
|
@router.get("", response_model=ApiResponse[dict], summary="全链路健康检查")
|
|||
|
|
def health_check() -> ApiResponse[dict]:
|
|||
|
|
"""服务/数据库/向量库/模型/Git/磁盘 全链路探活。"""
|
|||
|
|
result = check_all()
|
|||
|
|
code = 0 if result["status"] == "healthy" else 1
|
|||
|
|
return ApiResponse(
|
|||
|
|
code=code,
|
|||
|
|
message=f"整体状态:{result['status']}({result['healthy_count']}/{result['total_count']} 正常)",
|
|||
|
|
data=result,
|
|||
|
|
)
|