forked from xiaohei/taiji-AI-PAD
fix: 修复MCP Server启动问题
修复内容: 1. 修复docker-compose.yml中DATABASE_URL配置 - 从postgresql://改为postgresql+asyncpg:// - 确保使用正确的异步数据库驱动 2. 添加缺失的Prometheus Metrics定义 - HTTP请求指标 (http_requests_total, http_request_duration) - Agent管理指标 (agents_registered_total, agents_queries_total) - 工具调用指标 (tool_calls_total, function_tool_calls_total) - MCP协议指标 (mcp_requests_total, mcp_request_duration) - WebSocket指标 (websocket_connections_total, websocket_connections_active) - 系统健康指标 (redis_connections, nats_connections, database_connections, function_registry_size) 问题原因: - DATABASE_URL格式错误导致SQLAlchemy尝试使用psycopg2而非asyncpg - Prometheus metrics变量未定义导致启动时NameError 修复结果: - MCP Server现在可以正常启动并健康运行 - 所有Prometheus metrics正常工作
This commit is contained in:
+1
-1
@@ -111,7 +111,7 @@ services:
|
||||
ports:
|
||||
- "8002:8000"
|
||||
environment:
|
||||
- DATABASE_URL=postgresql://taiji_user:taiji_pass@postgres:5432/taiji_db
|
||||
- DATABASE_URL=postgresql+asyncpg://taiji_user:taiji_pass@postgres:5432/taiji_db
|
||||
- REDIS_URL=redis://redis:6379
|
||||
- NATS_URL=nats://nats:4222
|
||||
- LITELLM_URL=http://litellm-gateway:4000
|
||||
|
||||
@@ -77,6 +77,103 @@ app.add_middleware(
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# Prometheus Metrics定义
|
||||
# HTTP请求指标
|
||||
http_requests_total = Counter(
|
||||
"http_requests_total",
|
||||
"HTTP请求总数",
|
||||
["method", "endpoint", "status"]
|
||||
)
|
||||
http_request_duration = Histogram(
|
||||
"http_request_duration_seconds",
|
||||
"HTTP请求耗时(秒)",
|
||||
["method", "endpoint"]
|
||||
)
|
||||
|
||||
# Agent管理指标
|
||||
agents_registered_total = Counter(
|
||||
"agents_registered_total",
|
||||
"注册的Agent总数",
|
||||
["status"]
|
||||
)
|
||||
agents_queries_total = Counter(
|
||||
"agents_queries_total",
|
||||
"Agent查询总数",
|
||||
["query_type"]
|
||||
)
|
||||
agents_active_websockets = Gauge(
|
||||
"agents_active_websockets",
|
||||
"活跃的WebSocket连接数"
|
||||
)
|
||||
|
||||
# 工具调用指标
|
||||
tool_calls_total = Counter(
|
||||
"tool_calls_total",
|
||||
"工具调用总数",
|
||||
["tool_type", "status"]
|
||||
)
|
||||
tool_call_duration = Histogram(
|
||||
"tool_call_duration_seconds",
|
||||
"工具调用耗时(秒)",
|
||||
["tool_type"]
|
||||
)
|
||||
function_tool_calls_total = Counter(
|
||||
"function_tool_calls_total",
|
||||
"函数工具调用总数",
|
||||
["function_name", "status"]
|
||||
)
|
||||
function_tool_call_duration = Histogram(
|
||||
"function_tool_call_duration_seconds",
|
||||
"函数工具调用耗时(秒)",
|
||||
["function_name"]
|
||||
)
|
||||
|
||||
# MCP协议指标
|
||||
mcp_requests_total = Counter(
|
||||
"mcp_requests_total",
|
||||
"MCP请求总数",
|
||||
["method", "status"]
|
||||
)
|
||||
mcp_request_duration = Histogram(
|
||||
"mcp_request_duration_seconds",
|
||||
"MCP请求耗时(秒)",
|
||||
["method"]
|
||||
)
|
||||
|
||||
# WebSocket指标
|
||||
websocket_connections_total = Counter(
|
||||
"websocket_connections_total",
|
||||
"WebSocket连接总数",
|
||||
["status"]
|
||||
)
|
||||
websocket_connections_active = Gauge(
|
||||
"websocket_connections_active",
|
||||
"活跃的WebSocket连接数"
|
||||
)
|
||||
websocket_messages_total = Counter(
|
||||
"websocket_messages_total",
|
||||
"WebSocket消息总数",
|
||||
["direction"]
|
||||
)
|
||||
|
||||
# 系统健康指标
|
||||
redis_connections = Gauge(
|
||||
"redis_connections",
|
||||
"Redis连接状态(1=连接,0=断开)"
|
||||
)
|
||||
nats_connections = Gauge(
|
||||
"nats_connections",
|
||||
"NATS连接状态(1=连接,0=断开)"
|
||||
)
|
||||
database_connections = Gauge(
|
||||
"database_connections",
|
||||
"数据库连接状态(1=连接,0=断开)"
|
||||
)
|
||||
function_registry_size = Gauge(
|
||||
"function_registry_size",
|
||||
"函数注册表大小"
|
||||
)
|
||||
|
||||
# Prometheus Metrics中间件
|
||||
@app.middleware("http")
|
||||
async def metrics_middleware(request: Request, call_next):
|
||||
|
||||
Reference in New Issue
Block a user