PTP MCP服务器
模型上下文协议(MCP)服务器,用于监控和分析OpenShift集群中的精确时间协议(PTP)系统。
🚀 特性
- PTP配置分析:从OpenShift解析和验证PTP配置
- 实时日志监控:使用智能解析访问linuxptp守护进程日志
- 自然语言查询:用简单的英语询问有关PTP状态的问题
- 健康监测:全面的PTP系统健康检查
- 同步分析:监视同步状态、偏移和BMCA状态
- 时钟层次结构:跟踪特级大师和时钟层次信息
- ITU-T合规性:根据ITU-T G.8275.1标准验证配置
📋 先决条件
- Python 3.8或更高版本
- OpenShift命令行界面(
oc)已安装并配置 - 在安装了PTP操作员的情况下访问OpenShift集群
- PTP命名空间(
openshift-ptp)存在
🛠️ 安装
- 克隆存储库:
git clone https://github.com/aneeshkp/ptp-mcp-server.git
cd ptp-mcp-server- 安装依赖项:
pip install -r requirements.txt- 验证OpenShift访问权限:
oc whoami
oc get namespace openshift-ptp🧪 快速测试
运行综合测试套件:
python quick_test.py预期产量:
🔍 PTP MCP Server API Quick Test
==================================================
Tests Passed: 8/8
Success Rate: 100.0%
🎉 ALL TESTS PASSED! Your API is ready for agent integration.📚 API终点
1.配置API
from ptp_tools import PTPTools
tools = PTPTools()
result = await tools.get_ptp_config({"namespace": "openshift-ptp"})2.日志API
result = await tools.get_ptp_logs({"lines": 1000})3.搜索API
result = await tools.search_logs({"query": "dpll", "time_range": "last_hour"})4.卫生API
result = await tools.check_ptp_health({"check_config": True, "check_sync": True})5.自然语言API
result = await tools.query_ptp({"question": "What is the current grandmaster?"})6、特级大师状态API
result = await tools.get_grandmaster_status({"detailed": True})7.同步状态API
result = await tools.analyze_sync_status({"include_offsets": True})8.时钟层次结构API
result = await tools.get_clock_hierarchy({"include_ports": True})🚀 使用示例
基本健康检查
import asyncio
from ptp_tools import PTPTools
async def check_health():
tools = PTPTools()
health = await tools.check_ptp_health({})
if health["success"]:
print(f"Status: {health['overall_status']}")
for check_name, result in health["checks"].items():
print(f"{check_name}: {result}")
else:
print(f"Error: {health.get('error')}")
asyncio.run(check_health())自然语言查询
async def ask_question():
tools = PTPTools()
response = await tools.query_ptp({
"question": "What is the current grandmaster?"
})
if response["success"]:
print(f"Answer: {response['response']}")
else:
print(f"Error: {response.get('error')}")
asyncio.run(ask_question())日志分析
async def analyze_logs():
tools = PTPTools()
# Get recent logs
logs = await tools.get_ptp_logs({"lines": 500})
# Search for specific events
sync_loss = await tools.search_logs({"query": "sync loss"})
clock_changes = await tools.search_logs({"query": "clockClass change"})
print(f"Total logs: {logs['logs_count']}")
print(f"Sync loss events: {sync_loss['matching_logs']}")
print(f"Clock changes: {clock_changes['matching_logs']}")
asyncio.run(analyze_logs())🔧 MCP服务器
启动MCP服务器以与MCP兼容客户端集成:
python ptp_mcp_server.py服务器提供以下MCP工具:
get_ptp_config-获取PTP配置get_ptp_logs-获取linuxptp守护进程日志search_logs-在日志中搜索模式get_grandmaster_status-获取特级大师信息analyze_sync_status-分析同步状态get_clock_hierarchy-获取时钟层次结构check_ptp_health-全面健康检查query_ptp-自然语言界面
📊 演出
- 平均响应时间:0.78秒
- API最快:配置API(0.22s)
- 并行操作:2.45秒成功4/4
- 成功率:100%(8/8个终点)
🏗️ 建筑
ptp-mcp-server/
├── ptp_mcp_server.py # Main MCP server
├── ptp_config_parser.py # PTP configuration parser
├── ptp_log_parser.py # Linuxptp log parser
├── ptp_model.py # PTP data models
├── ptp_query_engine.py # Natural language query engine
├── ptp_tools.py # API endpoint implementations
├── quick_test.py # Quick test suite
├── performance_test.py # Performance benchmarking
└── requirements.txt # Python dependencies🔍 支持PTP概念
- BMCA(最佳主时钟算法):时钟选择和层次结构
- 时钟类型:OC(普通时钟)、BC(边界时钟)、TC(透明时钟)
- 国际电联第8275.1号:配置文件合规性和验证
- 同步:偏移跟踪、频率调整、同步状态
- 国际象棋特级大师:主要时间源标识和状态
- 时钟类:质量和可追溯性指标
- 域名:PTP域配置(ITU-T为24-43)
🧪 测试
运行所有测试
python quick_test.py性能测试
python performance_test.py单个组件测试
# Test configuration parser
python -c "from ptp_config_parser import PTPConfigParser; import asyncio; asyncio.run(PTPConfigParser().get_ptp_configs())"
# Test log parser
python -c "from ptp_log_parser import PTPLogParser; import asyncio; asyncio.run(PTPLogParser().get_ptp_logs())"📖 文档
🤝 贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
📄 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🙏 致谢
- OpenShift PTP操作员团队
- Linuxptp项目
- 模型上下文协议(MCP)社区
📞 支持
对于问题和疑问:
______________________________________________________________________
状态: ✅ 生产就绪\ 最后更新:2025年1月\ 版本: 1.0.0
