集群性能分析平台

OCP Performance Analyzer MCP是一款AI驱动的OpenShift/Kubernetes集群性能分析与监控平台,提供ETCD、网络和OVN-Kubernetes组件的深度性能分析、自动化根因分析及可操作建议。

  • by openshift-eng
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 openshift-eng/ocp-performance-analyzer-mcp

使用说明

OCP性能分析仪MCP

一个全面的、基于人工智能的OpenShift/Kubernetes集群性能分析和监控平台。该项目提供模型上下文协议(MCP)服务器,用于分析etcd、网络和OVN Kubernetes组件,并提供深入的性能见解、自动化的根本原因分析和可操作的建议。

目录

概述

OCP性能分析器MCP是一个多组件平台,旨在监控和分析OpenShift/Kubernetes集群在四个主要领域的性能:

  1. ETCD分析仪 -全面的etcd集群性能监控
  2. 网络分析仪 -网络堆栈性能分析(L1、套接字、netstat、I/O)
  3. OVN Kubernetes分析器 -OVN Kubernetes网络组件分析
  4. 节点分析器 -节点健康和性能监控(PLEG、运行时操作、资源使用)

每个组件包括:

  • MCP服务器公开性能分析工具
  • AI驱动的智能分析和报告代理
  • Prometheus指标的数据收集工具
  • ELT(提取-加载-转换)数据处理管道
  • 使用DuckDB的持久存储
  • 用于交互式分析的Web界面

建筑

高级体系结构

┌──────────────────────────────────────────────────────────┐
│                    Client Layer                          │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐    │
│  │   Web UI     │  │   CLI Tools  │  │   REST API   │    │
│  └──────┬───────┘  └──────┬───────┘  └──────┬───────┘    │
└─────────┼─────────────────┼─────────────────┼────────────┘
          │                 │                 │
          └─────────────────┼─────────────────┘
                            │
┌───────────────────────────┼───────────────────────────────┐
│                    AI Agent Layer (Port 8080)             │
│  ┌─────────────────────────────────────────────────────┐  │
│  │  LangGraph Agents: Chat, Report, Storage            │  │
│  │  • Streaming responses                              │  │
│  │  • Tool orchestration                               │  │
│  │  • Conversation memory                              │  │
│  └─────────────────────────────────────────────────────┘  │
└───────────────────────────┬───────────────────────────────┘
                            │ MCP Protocol
┌───────────────────────────┼─────────────────────────────────────────────────┐
│                    MCP Server Layer (Port 8000)                             │
│  ┌──────────────┐  ┌───────────────┐  ┌───────────────┐  ┌───────────────┐  │
│  │ ETCD Server  │  │ Network Server│  │ OVNK Server   │  │ Node Server   │  │
│  │ 15+ tools    │  │ 10+ tools     │  │ 8+ tools      │  │ 5+ tools      │  │
│  └───────┬──────┘  └────────┬──────┘  └────────┬──────┘  └────────┬──────┘  │
└──────────┼──────────────────┼──────────────────┼──────────────────┼─────────┘
           │                  │                  │                  │
┌──────────┼──────────────────┼──────────────────┼──────────────────┼──────────┐
│          │                  │                  │                  │          │
│  ┌───────▼───────┐  ┌───────▼───────┐  ┌───────▼───────┐  ┌───────▼───────┐  │
│  │   Tools/      │  │   Tools/      │  │   Tools/      │  │   Tools/      │  │
│  │   Collectors  │  │   Collectors  │  │   Collectors  │  │   Collectors  │  │
│  └───────┬───────┘  └───────┬───────┘  └───────┬───────┘  └───────┬───────┘  │
│          │                  │                  │                  │          │
│  ┌───────▼───────┐  ┌───────▼───────┐  ┌───────▼───────┐  ┌───────▼───────┐  │
│  │   Analysis    │  │   Analysis    │  │   Analysis    │  │   Analysis    │  │
│  │   Modules     │  │   Modules     │  │   Modules     │  │   Modules     │  │
│  └───────┬───────┘  └───────┬───────┘  └───────┬───────┘  └───────┬───────┘  │
│          │                  │                  │                  │          │
│  ┌───────▼───────┐  ┌───────▼───────┐  ┌───────▼───────┐  ┌───────▼───────┐  │
│  │   ELT         │  │   ELT         │  │   ELT         │  │   ELT         │  │
│  │   Pipeline    │  │   Pipeline    │  │   Pipeline    │  │   Pipeline    │  │
│  └───────┬───────┘  └───────┬───────┘  └───────┬───────┘  └───────┬───────┘  │
│          │                  │                  │                  │          │
│  ┌───────▼──────────────────▼──────────────────▼──────────────────▼───────┐  │
│  │              Storage Layer (DuckDB)                                    │  │
│  └────────────────────────────────────────────────────────────────────────┘  │
└──────────────────────────────────────────────────────────────────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────┐
│         OpenShift/Kubernetes Cluster Infrastructure         │
│  • ETCD Cluster    • Prometheus    • Kubernetes API         │
│  • Master Nodes    • OVN-Kubernetes • Network Components    │
└─────────────────────────────────────────────────────────────┘

组件体系结构

每个分析器(etcd、network、ovnk)都遵循一致的架构:

  1. MCP服务器 -基于FastMCP的服务器公开分析工具
  2. 工具/收藏家 -Prometheus查询的专用度量收集器
  3. 分析模块 -性能分析和瓶颈检测
  4. ELT管道 -数据转换和HTML表生成
  5. 存储模块 -DuckDB历史数据持久化
  6. AI智能体 -基于LangGraph的智能分析代理

特性

核心能力

  • 多组分分析:ETCD、网络和OVN Kubernetes分析器
  • MCP协议:用于工具公开的模型上下文协议服务器
  • AI驱动:与OpenAI集成的LangGraph代理
  • 实时监控:实时指标收集和分析
  • 历史分析:基于DuckDB的时间序列存储
  • 自动报告:执行就绪的绩效报告
  • Web界面:交互式聊天和分析UI
  • 流媒体响应:通过SSE实时传输结果

ETCD分析仪功能

  • 15+分析工具:群集状态、WAL fsync、后端提交、磁盘I/O、网络I/O、节点使用情况
  • 深度驱动分析:多个子系统综合评审
  • 瓶颈检测:自动识别性能问题
  • 性能报告:附有建议的执行摘要
  • 关键指标:WAL fsync P99(<10ms),后端提交P99(<25ms)

网络分析器功能

  • 10+分析工具:L1统计、套接字统计(TCP/UDP/IP/mem/softnet)、netstat、网络I/O
  • 多层分析:物理层到应用层指标
  • 性能指标:吞吐量、延迟、数据包统计、连接跟踪
  • 全面覆盖:9个类别的95个网络指标

OVN Kubernetes分析器功能

  • 8+分析工具:OVN数据库、kubelet CNI、延迟、OVS使用情况、pod指标、API统计数据
  • OVN特定指标:北向/南向数据库大小、同步性能
  • CNI分析:Kubelet和CNI性能指标
  • OVS监控:打开vSwitch守护进程和流表统计信息

节点分析器功能

  • 5+分析工具:节点资源使用情况、PLEG延迟、kubelet运行时操作错误、集群信息、健康状态
  • PLEG监测:Pod生命周期事件生成器重新列出具有可配置阈值的延迟指标
  • 运行时错误跟踪:Kubelet运行时操作错误率(按操作类型)
  • 资源指标:跨节点组(控制平面、工作区、基础设施、工作负载)的CPU、内存和c组使用情况
  • 节点组支持:按节点角色分组的指标,用于目标分析
  • Web用户界面:Markdown渲染的聊天界面,带有颜色编码的见解和建议

共享特征

  • 配置管理:基于YAML的度量配置(11个度量文件)
  • 认证:OpenShift/Kubernetes集群身份验证
  • 普罗米修斯集成:直接执行PromQL查询
  • 数据可视化:带突出显示的HTML表格生成
  • 导出功能:报告、数据导出、历史查询

项目结构

ocp-performance-analyzer-mcp/
│
├── analysis/                    # Performance analysis modules
│   ├── etcd/                    # ETCD-specific analysis
│   │   ├── etcd_performance_deepdrive.py
│   │   └── etcd_performance_report.py
│   ├── net/                     # Network analysis (future)
│   ├── node/                    # Node analysis (future)
│   ├── ovnk/                    # OVN-Kubernetes analysis (future)
│   └── utils/                   # Shared analysis utilities
│       └── analysis_utility.py
│
├── config/                      # Configuration management
│   ├── metrics_config_reader.py # Unified metrics loader
│   ├── metrics-alert.yml        # Alert metrics
│   ├── metrics-api.yml          # API server metrics
│   ├── metrics-cni.yml          # CNI metrics
│   ├── metrics-disk.yml         # Disk I/O metrics
│   ├── metrics-etcd.yml         # ETCD metrics (51 metrics)
│   ├── metrics-latency.yml      # Latency metrics
│   ├── metrics-net.yml           # Network metrics (95 metrics)
│   ├── metrics-node.yml          # Node metrics
│   ├── metrics-ovn.yml           # OVN metrics
│   ├── metrics-ovs.yml           # OVS metrics
│   ├── metrics-pods.yml          # Pod metrics
│   ├── README.md                 # Config documentation
│   └── test_metrics_loading.py   # Configuration tests
│
├── elt/                         # Extract-Load-Transform pipeline
│   ├── etcd/                    # ETCD ELT modules
│   │   ├── analyzer_elt_backend_commit.py
│   │   ├── analyzer_elt_bottleneck_analysis.py
│   │   ├── analyzer_elt_cluster_status.py
│   │   ├── analyzer_elt_compact_defrag.py
│   │   ├── analyzer_elt_general_info.py
│   │   ├── analyzer_elt_performance_deep_drive.py
│   │   ├── analyzer_elt_wal_fsync.py
│   │   └── etcd_analyzer_elt_*.py
│   ├── net/                     # Network ELT modules
│   │   ├── analyzer_elt_network_io.py
│   │   ├── analyzer_elt_network_l1.py
│   │   ├── analyzer_elt_network_netstat4*.py
│   │   └── analyzer_elt_network_socket4*.py
│   ├── node/                    # Node ELT modules
│   │   ├── analyzer_elt_node_usage.py
│   │   ├── analyzer_elt_node_pleg_relist.py
│   │   └── analyzer_elt_node_kubelet_runtime_operations_errors.py
│   ├── ocp/                     # OCP cluster ELT modules
│   │   ├── analyzer_elt_cluster_alert.py
│   │   ├── analyzer_elt_cluster_apistats.py
│   │   └── analyzer_elt_cluster_info.py
│   ├── ovnk/                    # OVN-Kubernetes ELT modules
│   │   ├── analyzer_elt_deepdrive.py
│   │   ├── analyzer_elt_kubelet_cni.py
│   │   ├── analyzer_elt_latency.py
│   │   └── analyzer_elt_ovs.py
│   ├── pods/                    # Pod ELT modules
│   │   └── analyzer_elt_pods_usage.py
│   ├── disk/                    # Disk ELT modules
│   │   └── analyzer_elt_disk_io.py
│   └── utils/                   # ELT utilities
│       ├── analyzer_elt_json2table.py  # Generic orchestrator
│       ├── analyzer_elt_utility.py      # Pure utilities
│       └── README.md                    # ELT documentation
│
├── mcp/                         # MCP servers and agents
│   ├── etcd/                    # ETCD analyzer MCP server
│   │   ├── etcd_analyzer_mcp_server.py      # Main MCP server
│   │   ├── etcd_analyzer_client_chat.py     # Chat client (FastAPI)
│   │   ├── etcd_analyzer_mcp_agent_report.py    # Report agent
│   │   ├── etcd_analyzer_mcp_agent_stor2db.py   # Storage agent
│   │   ├── etcd_analyzer_command.sh             # Management script
│   │   ├── etcd_analyzer_cluster.duckdb         # DuckDB database
│   │   ├── exports/                             # Report exports
│   │   ├── logs/                                # Application logs
│   │   ├── storage/                             # Storage modules
│   │   ├── pyproject.toml                       # Package config
│   │   └── README.md                            # ETCD docs
│   ├── net/                     # Network analyzer MCP server
│   │   ├── network_analyzer_mcp_server.py
│   │   ├── network_analyzer_client_chat.py
│   │   ├── network_analyzer_mcp_command.sh
│   │   ├── exports/
│   │   ├── logs/
│   │   └── storage/
│   ├── node/                    # Node analyzer MCP server
│   │   ├── node_analyzer_mcp_server.py      # Main MCP server
│   │   ├── node_analyzer_client_chat.py     # Chat client (FastAPI)
│   │   ├── mcp_tools/                       # Modular MCP tool definitions
│   │   │   ├── __init__.py
│   │   │   ├── models.py                    # Pydantic models
│   │   │   ├── health_check.py              # Health status tool
│   │   │   ├── cluster_info.py              # Cluster info tool
│   │   │   ├── node_usage.py                # Node usage tool
│   │   │   ├── node_pleg_relist.py          # PLEG latency tool
│   │   │   └── node_kubelet_runtime_operations_errors.py  # Runtime errors tool
│   │   ├── exports/
│   │   └── logs/
│   └── ovnk/                    # OVN-Kubernetes analyzer MCP server
│       ├── ovnk_analyzer_mcp_server.py
│       ├── ovnk_analyzer_mcp_client_chat.py
│       ├── ovnk_analyzer_mcp_command.sh
│       ├── exports/
│       ├── logs/
│       ├── storage/
│       └── README.md
│
├── ocauth/                      # OpenShift authentication
│   └── openshift_auth.py        # K8s/OCP auth, token management
│
├── storage/                     # DuckDB storage modules
│   ├── etcd/                    # ETCD storage modules
│   │   ├── analyzer_stor_backend_commit.py
│   │   ├── analyzer_stor_cluster_info.py
│   │   ├── analyzer_stor_compact_defrag.py
│   │   ├── analyzer_stor_disk_io.py
│   │   ├── analyzer_stor_disk_wal_fsync.py
│   │   ├── analyzer_stor_general_info.py
│   │   ├── analyzer_stor_network_io.py
│   │   └── analyzer_stor_utility.py
│   ├── net/                     # Network storage (future)
│   └── ovnk/                    # OVN-Kubernetes storage (future)
│
├── tools/                       # Metric collection tools
│   ├── etcd/                    # ETCD collectors
│   │   ├── etcd_cluster_status.py
│   │   ├── etcd_general_info.py
│   │   ├── etcd_disk_wal_fsync.py
│   │   ├── etcd_disk_backend_commit.py
│   │   └── etcd_disk_compact_defrag.py
│   ├── net/                     # Network collectors
│   │   ├── network_io.py
│   │   ├── network_l1.py
│   │   ├── network_netstat4tcp.py
│   │   ├── network_netstat4udp.py
│   │   ├── network_socket4tcp.py
│   │   ├── network_socket4udp.py
│   │   ├── network_socket4ip.py
│   │   ├── network_socket4mem.py
│   │   └── network_socket4softnet.py
│   ├── node/                    # Node collectors
│   │   ├── node_usage.py
│   │   ├── node_pleg_relist.py
│   │   └── node_kubelet_runtime_operations_errors.py
│   ├── ocp/                     # OCP collectors
│   │   ├── cluster_info.py
│   │   ├── cluster_apistats.py
│   │   └── cluster_alert.py
│   ├── ovnk/                    # OVN-Kubernetes collectors
│   │   ├── ovnk_baseinfo.py
│   │   ├── ovnk_kubelet_cni.py
│   │   ├── ovnk_latency.py
│   │   └── ovnk_ovs_usage.py
│   ├── pods/                    # Pod collectors
│   │   └── pods_usage.py
│   ├── disk/                    # Disk collectors
│   │   └── disk_io.py
│   └── utils/                   # Shared utilities
│       ├── promql_basequery.py  # Base Prometheus queries
│       └── promql_utility.py     # PromQL helpers
│
├── webroot/                     # Web interfaces
│   ├── etcd/                    # ETCD web UI
│   │   └── etcd_analyzer_mcp_llm.html
│   ├── net/                     # Network web UI
│   │   └── network_analyzer_mcp_llm.html
│   ├── node/                    # Node web UI
│   │   └── node_analyzer_mcp_llm.html
│   └── ovnk/                    # OVN-Kubernetes web UI
│       └── ovnk_analyzer_mcp_llm.html
│
├── exports/                     # Generated reports and exports
├── logs/                        # Application logs
├── pyproject.toml               # Main project configuration
├── LICENSE                      # License file
└── README.md                    # This file

安装

先决条件

  • Python 3.8或更高版本
  • 访问OpenShift/Kubernetes集群
  • KUBECONFIG已配置
  • 普罗米修斯/灭霸可用
  • OpenAI API密钥(用于AI功能)

步骤1:克隆存储库

git clone https://github.com/liqcui/ocp-performance-analyzer-mcp.git
cd ocp-performance-analyzer-mcp

第二步:创建虚拟环境

python3 -m venv venv
source venv/bin/activate  # Linux/Mac
# or
venv\Scripts\activate  # Windows

步骤3:安装依赖项

pip install -e .

或者从根目录安装 pyproject.toml:

pip install -r requirements.txt  # If available

关键依赖关系:

  • fastmcp>=1.12.4 -MCP服务器框架
  • fastapi>=0.115.7 -Web框架
  • langchain>=0.3.0 -LLM集成
  • langgraph>=0.3.0 -代理编排
  • duckdb>=1.0.0 -时间序列数据库
  • kubernetes>=30.0.0 -Kubernetes客户端
  • prometheus-api-client>=0.5.3 -Prometheus查询
  • pydantic>=2.0.0 -数据验证
  • pandas>=2.2.0 -数据处理
  • pyyaml>=6.0.1 -配置解析

步骤4:配置环境

创建 .env 文件(可选):

# OpenAI-compatible API configuration
OPENAI_API_KEY=your-api-key-here
BASE_URL=https://your-llm-api-endpoint

# OpenShift configuration
KUBECONFIG=/path/to/your/kubeconfig

# Optional: MCP Inspector
ENABLE_MCP_INSPECTOR=0
MCP_INSPECTOR_URL=http://127.0.0.1:8000/sse

步骤5:验证KUBECONFIG

export KUBECONFIG=/path/to/kubeconfig
kubectl get nodes
oc get clusterversion  # For OpenShift

快速开始

ETCD分析仪

cd mcp/etcd

# Start MCP server
./etcd_analyzer_command.sh start

# Or manually
python etcd_analyzer_mcp_server.py

# Start chat client (in another terminal)
python etcd_analyzer_client_chat.py

# Access web UI
open http://localhost:8080/ui

网络分析仪

cd mcp/net

# Start MCP server
./network_analyzer_mcp_command.sh start

# Or manually
python network_analyzer_mcp_server.py

# Start chat client
python network_analyzer_client_chat.py

OVN Kubernetes分析器

cd mcp/ovnk

# Start MCP server
./ovnk_analyzer_mcp_command.sh start

# Or manually
python ovnk_analyzer_mcp_server.py

# Start chat client
python ovnk_analyzer_mcp_client_chat.py

节点分析器

cd mcp/node

# Start MCP server (Port 8004)
python node_analyzer_mcp_server.py

# Start chat client (Port 8084) in another terminal
python node_analyzer_client_chat.py

# Access web UI
open http://localhost:8084/ui

组件

1.MCP服务器

每个分析器都使用专用工具公开一个MCP服务器:

ETCD MCP服务器(mcp/etcd/etcd_analyzer_mcp_server.py)

工具:

  • get_server_health -服务器健康检查
  • get_etcd_cluster_status -通过etcdctl获取集群健康状况
  • get_ocp_cluster_info -集群信息
  • get_etcd_general_info -一般etcd指标
  • get_etcd_node_usage -主节点指标
  • get_etcd_disk_wal_fsync -WAL fsync性能
  • get_etcd_disk_backend_commit -后端提交性能
  • get_node_disk_io -磁盘I/O指标
  • get_etcd_disk_compact_defrag -压缩/碎片整理指标
  • get_etcd_network_io -网络I/O指标
  • get_etcd_performance_deep_drive -综合分析
  • get_etcd_bottleneck_analysis -瓶颈检测
  • generate_etcd_performance_report -执行报告

网络MCP服务器(mcp/net/network_analyzer_mcp_server.py)

工具:

  • get_ocp_cluster_info -集群信息
  • query_network_l1_metrics -第1层网络统计
  • query_network_io_metrics -网络I/O性能
  • query_network_socket_tcp_metrics -TCP套接字统计
  • query_network_socket_udp_metrics -UDP套接字统计
  • query_network_socket_ip_metrics -IP套接字统计
  • query_network_socket_mem_metrics -套接字内存统计
  • query_network_socket_softnet_metrics -软网统计
  • query_network_netstat_tcp_metrics -TCP网络统计指标
  • query_network_netstat_udp_metrics -UDP网络统计指标

OVN Kubernetes MCP服务器(mcp/ovnk/ovnk_analyzer_mcp_server.py)

工具:

  • get_ocp_cluster_info -集群信息
  • query_ovnk_pod_metrics -OVN Kubernetes pod指标
  • query_multus_pod_metrics -Multus CNI指标
  • query_ovnk_container_metrics -OVN容器指标
  • query_ovnk_sync_metrics -OVN同步度量
  • query_ovnk_ovs_metrics -OVS守护进程指标
  • query_ovnk_latency_metrics -网络延迟指标
  • query_kube_api_metrics -Kubernetes API指标

节点MCP服务器(mcp/node/node_analyzer_mcp_server.py)

工具:

  • get_server_health -服务器健康检查和收集器初始化状态
  • get_ocp_cluster_info -集群信息和节点清单
  • get_ocp_node_usage -按节点组划分的节点资源使用情况(CPU、内存、cgroup)
  • get_ocp_node_pleg_latency -PLEG重新列出具有阈值的延迟指标
    • 健康:<1s
    • 警告:1-10s
    • 严重:>10秒(默认),可配置为3分钟
  • get_ocp_node_runtime_errors -Kubelet运行时操作错误率
    • 健康:<0.01错误/秒
    • 警告:0.01-0.1错误/秒
    • 严重:0.1-1错误/秒
    • 严重:>1个错误/秒

特征:

  • 模块化工具架构 mcp_tools/ 目录
  • 节点组支持(控制平面、工作人员、基础设施、工作负载)
  • 具有节点级指标的全面健康状况摘要
  • 基于Markdown的聊天界面,语法高亮显示
  • 实时流媒体响应

2.工具/收藏家

按类别组织的专业收藏家:

  • ETCD:集群状态、一般信息、WAL fsync、后端提交、压缩/碎片整理
  • 网络:I/O、L1、套接字(TCP/UDP/IP/mem/softnet)、netstat(TCP/UDP)
  • 节点:CPU、内存、cgroup使用情况、PLEG重新列表延迟、kubelet运行时操作错误
    • nodeUsageCollector -节点资源指标(CPU、内存、cgroup)
    • plegRelistCollector -Pod生命周期事件生成器延迟指标
    • kubeletRuntimeOperationsErrorsCollector -按类型划分的运行时操作错误率
  • 开闭原则:群集信息、API统计数据、警报
  • OVNK:OVN数据库、kubelet CNI、延迟、OVS使用情况
  • 容器组:Pod和容器指标
  • 磁盘:磁盘I/O性能

3.分析模块

性能分析和报告:

  • 深度驱动分析:多个子系统综合评审
  • 瓶颈检测:自动问题识别
  • 性能报告:附有建议的执行摘要
  • 基线比较:当前绩效与目标绩效
  • 根本原因分析:基于脚本+人工智能驱动的RCA

4.ELT管道

提取负载变换以进行数据处理:

  • 通用编排器:将数据路由到特定指标的处理程序
  • 度量处理程序:每种公制类型的专业ELT模块
  • HTML生成:带突出显示的格式化表格
  • 数据转换:JSON转换为结构化DataFrames

5.存储层

基于DuckDB的持久存储:

  • 时间序列数据:高效的临时数据存储
  • 模式管理:自动创建和迁移表
  • 查询接口:基于SQL的数据访问
  • 历史分析:长期绩效跟踪

6.人工智能代理

基于LangGraph的智能代理:

  • 聊天代理:具有工具执行功能的对话界面
  • 报告代理:自动生成性能报告
  • 存储代理:数据收集和持久化

配置

指标配置

度量在YAML文件中定义,位于 config/:

  • metrics-etcd.yml -5个类别的51个ETCD指标
  • metrics-net.yml -9个类别的95个网络指标
  • metrics-api.yml -15 API服务器指标
  • metrics-disk.yml -8个磁盘I/O指标
  • metrics-node.yml -5个节点指标
  • metrics-ovn.yml -2个OVN指标
  • metrics-ovs.yml -18个OVS指标
  • metrics-pods.yml -6个吊舱指标
  • metrics-cni.yml -18个CNI指标
  • metrics-latency.yml -18个延迟指标
  • metrics-alert.yml -警报指标

看 config/README.md 查看详细的配置文档。

环境变量

# Required
export KUBECONFIG=/path/to/kubeconfig

# Optional - automatically set to UTC
export TZ=UTC

# LLM Configuration
export OPENAI_API_KEY=your-api-key
export BASE_URL=https://api.openai.com/v1

# MCP Inspector (optional)
export ENABLE_MCP_INSPECTOR=1
export MCP_INSPECTOR_URL=http://127.0.0.1:8000/sse

# Logging
export LOG_LEVEL=INFO
export OVNK_LOG_LEVEL=INFO

性能阈值

默认阈值(可在分析模块中配置):

thresholds = {
    'wal_fsync_p99_ms': 10.0,              # Critical for write performance
    'backend_commit_p99_ms': 25.0,         # Critical for persistence
    'cpu_usage_warning': 70.0,             # Pod CPU warning
    'cpu_usage_critical': 85.0,            # Pod CPU critical
    'memory_usage_warning': 70.0,           # Pod memory warning
    'memory_usage_critical': 85.0,         # Pod memory critical
    'peer_latency_warning_ms': 50.0,       # Network warning
    'peer_latency_critical_ms': 100.0,     # Network critical
    'network_utilization_warning': 70.0,   # Network utilization warning
    'network_utilization_critical': 85.0,  # Network utilization critical
}

使用示例

示例1:ETCD性能分析

# Start ETCD analyzer
cd mcp/etcd
./etcd_analyzer_command.sh start

# In web UI, ask:
"Analyze etcd performance for the last hour"
"Show me WAL fsync performance"
"Generate a performance report for the last 24 hours"

示例2:网络分析

# Start network analyzer
cd mcp/net
python network_analyzer_mcp_server.py

# Query network metrics
curl -X POST http://localhost:8000/tools/query_network_io_metrics \
  -H "Content-Type: application/json" \
  -d '{"duration": "1h"}'

示例3:OVN Kubernetes分析

# Start OVN-Kubernetes analyzer
cd mcp/ovnk
python ovnk_analyzer_mcp_server.py

# Query OVN metrics
curl -X POST http://localhost:8000/tools/query_ovnk_pod_metrics \
  -H "Content-Type: application/json" \
  -d '{"duration": "1h"}'

示例4:绩效报告生成

# Using ETCD report agent
cd mcp/etcd
python etcd_analyzer_mcp_agent_report.py

# Follow prompts:
# 1. Select duration mode or time range mode
# 2. Enter duration (e.g., "1h") or time range
# 3. View streaming analysis and report

示例5:数据存储

# Using ETCD storage agent
cd mcp/etcd
python etcd_analyzer_mcp_agent_stor2db.py

# Data stored in etcd_analyzer_cluster.duckdb
# Query stored data:
python -c "
import duckdb
conn = duckdb.connect('etcd_analyzer_cluster.duckdb')
result = conn.execute('SELECT * FROM wal_fsync_p99_latency LIMIT 10').fetchall()
print(result)
"

api参考

MCP服务器端点

所有MCP服务器都通过HTTP/SSE公开工具:

  • 基本URL: http://localhost:8000
  • 健康检查: GET /health
  • 工具: POST /tools/{tool_name}

聊天客户端端点

AI聊天客户端公开REST API:

  • 基本URL: http://localhost:8080
  • Web用户界面: GET /ui 或 GET /
  • 流媒体聊天: POST /chat/stream
  • 非流媒体聊天: POST /chat
  • 健康: GET /api/mcp/health
  • 工具列表: GET /api/tools

刀具参数

跨工具的通用参数:

  • duration (str):持续时间(例如,“5m”、“1h”、“24h”)
  • start_time (str,可选):ISO格式的开始时间
  • end_time (str,可选):ISO格式的结束时间

有关API的详细文档,请参阅单个组件自述文件:

  • mcp/etcd/README.md -ETCD分析仪API
  • mcp/ovnk/README.md -OVN-Kubernetes分析器API
  • config/README.md -配置API
  • elt/utils/README.md -API ELT管道

故障排除

常见问题

1.MCP服务器无法启动

解决:

# Check KUBECONFIG
echo $KUBECONFIG
kubectl get nodes

# Check if port 8000 is in use
lsof -i :8000

# Check logs
tail -f logs/mcp_server_*.log

2.身份验证失败

解决:

# Verify KUBECONFIG
export KUBECONFIG=/path/to/kubeconfig
kubectl auth can-i get pods -n openshift-etcd

# Check Prometheus access
kubectl get route -n openshift-monitoring

3.缺失指标

解决:

# Verify Prometheus is accessible
oc get pods -n openshift-monitoring | grep prometheus

# Check metric availability
oc exec -n openshift-monitoring prometheus-k8s-0 -- \
  promtool query instant http://localhost:9090 \
  'etcd_disk_wal_fsync_duration_seconds_bucket'

4.LLM API错误

解决:

# Check .env file
cat .env | grep OPENAI_API_KEY

# Test API connection
curl -H "Authorization: Bearer $OPENAI_API_KEY" \
  $BASE_URL/models

调试模式

启用详细日志记录:

export LOG_LEVEL=DEBUG
export OVNK_LOG_LEVEL=DEBUG
python mcp/etcd/etcd_analyzer_mcp_server.py

贡献

开发设置

# Clone repository
git clone https://github.com/liqcui/ocp-performance-analyzer-mcp.git
cd ocp-performance-analyzer-mcp

# Create development environment
python3 -m venv venv
source venv/bin/activate

# Install in development mode
pip install -e .

# Install development dependencies
pip install pytest pytest-asyncio black flake8 mypy

代码风格

# Format code
black .

# Lint code
flake8 .

# Type checking
mypy .

添加新指标

  1. 以适当的方式定义度量 config/metrics-*.yml 文件
  2. 添加收集器 tools/{category}/ 目录
  3. 在中添加ELT处理程序 elt/{category}/ 目录
  4. 在中添加存储模块 storage/{category}/ 目录
  5. 在MCP服务器中注册工具
  6. 更新文档

测试

# Run tests
pytest

# Run with coverage
pytest --cov=. --cov-report=html

许可证

MIT许可证-有关详细信息,请参阅许可证文件。

支持

对于问题和疑问:

  1. 检查故障排除部分
  2. 查看特定组件的自述文件
  3. 检查登录 logs/ 目录
  4. 打开一个包含详细日志和配置的问题

致谢

路线图

计划的功能

  • []多集群支持
  • []历史趋势分析
  • []使用ML进行异常检测
  • []自定义警报规则
  • []Grafana集成
  • []Slack/Teams通知
  • []性能预测
  • []自动补救建议
  • []Kubernetes原生部署(Helm charts)
  • []实时流媒体指标

内置于❤️ 面向OpenShift和Kubernetes社区