🔍 Cassandra日志分析器MCP
一个模型上下文协议(MCP)服务器,用于使用Claude AI分析和排除Apache Cassandra集群日志。
🌟 特性
- 🔐 SSH集成:直接连接到远程Cassandra节点
- 📊 自动化分析:针对常见Cassandra问题的智能模式检测
- 🔍 日志解析:解析system.log和debug.log文件
- 🚨 问题检测:自动检测超时、OOM、GC暂停、墓碑等。
- 💡 智能推荐:根据检测到的问题获得可操作的建议
- 📈 节点比较:比较多个节点之间的指标
- 🔎 模式搜索:使用正则表达式模式搜索日志
- 🌐 多节点支持:同时分析整个集群
📋 先决条件
- Python 3.10或更高版本
- 克劳德桌面
- SSH访问Cassandra节点
- Apache Cassandra集群
🚀 快速开始
1.克隆存储库
git clone https://github.com/NLatarche/cassandra-mcp.git
cd cassandra-mcp2.创建虚拟环境
python -m venv venv
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate3.安装依赖项
pip install -r requirements.txt4.配置克劳德桌面
编辑您的Claude Desktop配置文件:
视窗: %APPDATA%\Claude\claude_desktop_config.json\ macOS: ~/Library/Application Support/Claude/claude_desktop_config.json\ Linux: ~/.config/Claude/claude_desktop_config.json
添加MCP服务器配置:
{
"mcpServers": {
"cassandra-logs": {
"command": "/path/to/venv/bin/python",
"args": [
"/path/to/cassandra_log_analyzer.py"
]
}
}
}5.重新启动克劳德桌面
退出并重新启动Claude Desktop以加载MCP服务器。
💻 用法
配置对节点的SSH访问
Configure my 3 Cassandra nodes:
- node1: xx.xxx.xxx.xxx, user: admin, key: ~/.ssh/id_rsa
- node2: xxx.xxx.xxx.xxx, user: admin, key: ~/.ssh/id_rsa
- node3: xxx.xxx.xxx.xxx, user: admin, key: ~/.ssh/id_rsa从所有节点加载日志
Load the last 5000 lines of system.log from all nodes分析集群
Analyze the cluster and give me a detailed report with recommendations搜索具体问题
Search for all timeout errors in the logsAre there any critical errors in the last 24 hours?比较节点
Compare the performance metrics between the 3 nodes🛠️ 可用工具
MCP服务器提供9个工具:
- configure_sh_node -配置与Cassandra节点的SSH连接
- load_logs_from_ssh -通过SSH从节点加载日志
- load_logs_from_all_nodes -从所有配置的节点加载日志
- load_logs -手动加载日志(复制粘贴)
- analyze_cluster -执行完整的聚类分析
- search_logs -使用正则表达式模式搜索日志
- get_errors -从日志中提取所有错误
- 比较节点 -比较节点之间的指标
- 检测问题 -检测已知的Cassandra问题
🔍 检测到的问题
分析仪自动检测:
错误
- ⏱️ 超时(读/写/协调)
- 💾 内存不足(OOM)
- 🔌 连接问题
- 🗜️ 压实失败
- 🔧 维修失败
- 🗑️ GC暂停
- ⚰️ 墓碑警告
- 📉 已删除邮件
- ❌ 不可用的例外情况
警告
- 📊 堆压力
- 🐌 查询速度慢
- 📦 大批量
- 📡 流媒体问题
📊 示例分析输出
# Cassandra Cluster Analysis
## Summary by Node
### cassandra-node-1
- Errors: 23
- Warnings: 45
- Total lines: 5000
### cassandra-node-2
- Errors: 18
- Warnings: 38
- Total lines: 5000
### cassandra-node-3
- Errors: 31
- Warnings: 52
- Total lines: 5000
## Detected Issues
- timeout: 15 occurrences
- gc: 8 occurrences
- tombstone: 6 occurrences
## Recommendations
🔴 **Timeouts fréquents** (HIGH)
→ Check network latency, increase timeouts, or optimize queries
🟠 **GC Pauses excessives** (HIGH)
→ Optimize JVM heap, consider G1GC, or reduce load🏗️ 建筑
┌─────────────────────────────────┐
│ User │
│ "Analyze my Cassandra logs" │
└────────────┬────────────────────┘
│
↓ Natural language
┌─────────────────────────────────┐
│ Claude Desktop │
│ - Understands request │
│ - Calls appropriate tools │
└────────────┬────────────────────┘
│
↓ MCP Protocol
┌─────────────────────────────────┐
│ MCP Server (Python) │
│ - SSH connection management │
│ - Log parsing & analysis │
│ - Issue detection │
└────────────┬────────────────────┘
│
↓ SSH
┌─────────────────────────────────┐
│ Cassandra Nodes (Remote) │
│ - system.log │
│ - debug.log │
└─────────────────────────────────┘🔒 安全考虑
- SSH密钥存储在本地,从不传输
- 支持SSH密钥身份验证(推荐)
- 还支持密码身份验证
- 所有连接都使用标准SSH安全
- 没有数据发送到外部服务
🤝 贡献
欢迎投稿!请随时提交拉取请求。
- 分叉存储库
- 创建功能分支(
git checkout -b feature/AmazingFeature) - 提交您的更改(
git commit -m 'Add some AmazingFeature') - 推到分支(
git push origin feature/AmazingFeature) - 打开拉取请求
🙏 致谢
- 内置于 模型上下文协议(MCP)
- 由...驱动 克劳德 通过Anthropic
- SSH功能通过 参数
📧 联系
项目链接:
🗺️ 路线图
- \[\]实时日志流
- \[\]与nodetool指标集成
- \[\]性能指标分析
- \[\]自动警报
- \[\]报告生成(PDF/HTML)
- \[\]支持其他日志格式
- \[\]用于可视化的Web仪表板
______________________________________________________________________
备注:此工具专为日志分析和故障排除而设计。访问生产系统时,始终遵循组织的安全策略。
