-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Labels
enhancementNew feature or requestNew feature or request
Description
功能描述
提供工具调用的监控、统计和分析功能,帮助开发者了解工具使用情况并优化性能。
使用场景
from lc2mcp_server import MCPServer
from lc2mcp_server.monitoring import enable_monitoring
server = MCPServer()
enable_monitoring(server,
dashboard_port=8080,
retention_days=30
)访问 http://localhost:8080/dashboard 查看仪表盘。
仪表盘功能
1. 实时监控
- 当前活跃连接数
- 实时请求 QPS
- 工具调用成功/失败率
- 平均响应时间
2. 工具统计
- 各工具调用次数排名
- 工具调用耗时分布
- 工具错误率统计
- 参数使用分析
3. 用户分析
- 用户调用量统计
- 用户活跃度趋势
- 按平台分布 (ChatGPT/Claude/Cursor)
4. 性能分析
- 请求耗时 P50/P95/P99
- 慢查询分析
- 资源使用情况 (CPU/内存)
数据存储
monitoring:
backend: sqlite # sqlite / postgresql / prometheus
retention_days: 30
# Prometheus 集成
prometheus:
enabled: true
port: 9090
# 自定义指标导出
exporters:
- type: webhook
url: "https://your-analytics.com/ingest"API 接口
from lc2mcp_server.monitoring import get_metrics
# 获取统计数据
metrics = await get_metrics(
start_time="2024-01-01",
end_time="2024-01-31",
group_by="tool"
)
# 获取慢查询
slow_queries = await get_slow_queries(
threshold_ms=1000,
limit=100
)告警功能
alerts:
- name: high_error_rate
condition: "error_rate > 0.1"
duration: 5m
notify:
- slack: "#alerts"
- email: "admin@example.com"
- name: slow_response
condition: "p95_latency > 5000ms"
duration: 10m
notify:
- webhook: "https://pagerduty.com/..."任务清单
- 设计监控数据模型
- 实现数据收集中间件
- 实现数据存储层
- 开发 Web 仪表盘 UI
- 添加实时图表
- 实现告警系统
- 支持 Prometheus 导出
- 添加 API 接口
- 编写文档
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request