使用说明
项目简介
AINFRA(A Infrastructure Project)是一个基础设施监控项目,旨在通过模块化的微服务架构提供设备监控、性能指标收集、自定义设备集成和AI交互能力。其核心亮点在于集成了Model Context Protocol (MCP) 服务器,使得大型语言模型(LLM)客户端能够以标准化的方式访问平台管理的设备数据、触发自定义操作以及获取汇总的系统统计信息。这为构建由LLM驱动的自动化运维和智能报告应用奠定了基础。
主要功能点
- 设备管理: 支持添加、监控和管理不同类型的设备,包括基于Glances的标准服务器以及通过自定义插件集成的各类网络设备。
- 自定义设备插件: 提供灵活的插件机制,用户可以编写Python代码来定义和扩展对任意可联网设备的监控和控制能力(如ESXi、Synology NAS、Proxmox、智能电视等)。
- 性能监控: 对于标准设备,能够收集CPU、内存、磁盘、网络等详细性能指标。此功能依赖于在目标设备上运行Glances。
- 可用性监控: 定期自动检查设备的在线状态(通过Ping和端口扫描),记录可用性历史并生成概览统计。
- 传感器与告警: 允许在标准设备的关键性能指标上设置阈值传感器,并在条件满足时触发告警。
- AI交互: 内置一个LLM微服务(当前支持OpenAI),该服务作为MCP客户端与核心监控平台的MCP服务器通信,使得用户或自动化流程可以通过自然语言或LLM调用来查询设备状态、获取统计报告、执行设备操作等。
- 动态UI: 前端界面能够根据自定义设备的插件定义动态生成展示和操作界面。
安装步骤
要运行AINFRA平台,需要先准备好必要的环境:
- 安装必备工具: 确保您的系统已安装 Git、Docker 和 Docker Compose。
- 克隆仓库: 打开终端,克隆AINFRA仓库:
git clone https://github.com/n1kozor/AINFRA.git cd AINFRA - 构建并启动服务: 使用Docker Compose构建并启动AINFRA的各个微服务:
这会启动前端、主应用(含MCP服务器)、可用性监控服务和LLM服务。docker build . -t ainfra-image # 可选,如果需要自定义构建 docker-compose up -d - (针对标准设备监控) 在目标设备上运行Glances: 对于您希望使用AINFRA监控的标准服务器(Windows, Linux, Mac),需要在这些目标设备上安装并以Web服务器模式运行Glances。推荐使用Docker方式运行:
或者,如果您在目标设备上直接安装了Glances,运行 'glances -w'。确保AINFRA核心服务可以访问目标设备的Glances Web端口(默认为61208)。# 在您要监控的目标设备上运行此命令 docker run -d --restart="always" -p 61208-61209:61208-61209 -e GLANCES_OPT="-w" \ -v /var/run/docker.sock:/var/run/docker.sock:ro \ -v /run/user/1000/podman/podman.sock:/run/user/1000/podman/podman.sock:ro \ --pid host nicolargo/glances:latest - 配置LLM服务: 首次启动后,通过访问前端界面(通常在 'http://localhost:3000')进入设置页面,配置您的OpenAI API Key。这是启用LLM聊天和报告功能所必需的。
服务器配置 (供MCP客户端连接)
AINFRA平台的核心应用服务(通过'app/main.py'实现)集成了'fastapi-mcp'库,使其成为一个MCP服务器。该MCP服务器默认运行在 端口 8000,并通过 /api/v1/mcp 路径提供MCP服务。
要连接AINFRA的MCP服务器,任何符合MCP规范的客户端都需要知道如何连接并了解服务器的能力。以下是用于配置MCP客户端连接AINFRA MCP服务器的典型信息结构。请根据您的实际部署环境(例如,如果MCP客户端与AINFRA服务不在同一Docker网络或主机上)调整连接地址和端口。
{ "server_name": "AINFRA Monitoring Platform", "description": "Provides access to device monitoring data, custom device metrics and operations, system statistics, sensors, and alerts via MCP.", "command": ["http"], "args": [ "--url", "http://localhost:8000/api/v1/mcp", "--protocol", "json-rpc", "--encoding", "json" ], "capabilities": [ {"type": "Tool", "name": "get_all_devices", "description": "Retrieves a list of all managed devices."}, {"type": "Tool", "name": "get_device_by_id", "description": "Retrieves details for a specific device by ID."}, {"type": "Tool", "name": "get_standard_device_stats", "description": "Gets comprehensive system statistics from a standard device (requires Glances). Takes device_id."}, {"type": "Tool", "name": "get_standard_device_metric", "description": "Gets a specific system metric from a standard device (requires Glances). Takes device_id and metric."}, {"type": "Tool", "name": "get_custom_device_status", "description": "Gets status information from a custom device using its plugin. Takes device_id."}, {"type": "Tool", "name": "get_custom_device_metrics", "description": "Gets detailed metrics from a custom device using its plugin. Takes device_id."}, {"type": "Tool", "name": "get_custom_device_operations", "description": "Lists available operations and examples for a custom device plugin. Takes device_id."}, {"type": "Tool", "name": "execute_custom_device_operation", "description": "Executes a specific operation on a custom device using its plugin. Takes device_id, operation_id, and optional params."}, {"type": "Tool", "name": "get_all_plugins", "description": "Retrieves a list of all installed plugins."}, {"type": "Tool", "name": "get_plugin_by_id", "description": "Retrieves details for a specific plugin by ID."}, {"type": "Tool", "name": "get_plugin_template", "description": "Gets the standard plugin code template."}, {"type": "Tool", "name": "get_all_sensors", "description": "Retrieves a list of all configured sensors."}, {"type": "Tool", "name": "get_device_sensors", "description": "Retrieves sensors configured for a specific device. Takes device_id."}, {"type": "Tool", "name": "get_sensor_by_id", "description": "Retrieves details for a specific sensor by ID."}, {"type": "Tool", "name": "get_active_alerts", "description": "Retrieves all currently active (non-resolved) alerts. Optional device_id filter."}, {"type": "Tool", "name": "get_alert_history", "description": "Retrieves alert history for a specified period. Optional device_id and days filter."}, {"type": "Tool", "name": "resolve_alert", "description": "Manually marks an alert as resolved. Takes alert_id."}, {"type": "Tool", "name": "get_all_system_statistics", "description": "Retrieves comprehensive monitoring statistics and system overview. Optional time_range filter."} // Note: Operations like creating, updating, or deleting devices, plugins, or sensors // are generally excluded from the MCP tools exposed for LLMs for security reasons. // For the full API documentation (including CRUD endpoints), visit the /docs path on the main service (port 8000). ] }
请注意:上述JSON是给MCP客户端程序看的配置示例,不是需要在AINFRA中手动运行的命令。实际的MCP客户端(如AINFRA自身的LLM服务)会读取并使用这些信息来连接AINFRA的MCP服务器。示例中的'"http://localhost:8000/api/v1/mcp"'是AINFRA MCP服务器的默认访问地址。
基本使用方法
- 访问前端: 在浏览器中打开 'http://localhost:3000' 即可访问AINFRA的用户界面。
- 添加设备: 前往"Devices"页面,点击添加按钮,选择设备类型(标准或自定义),填写必要信息(如IP地址、Glances主机名或自定义设备的连接参数),并保存。
- 监控设备: 在"Devices"或"Dashboard"页面查看设备的可用性状态和性能指标。标准设备的详细指标需要确保目标设备上的Glances正在运行。
- 管理插件: 如果您需要监控自定义设备类型,可以前往"Plugins"页面上传或创建插件代码。
- 创建传感器: 对于标准设备,可以在设备详情页或"Sensors"页面创建传感器,定义要监控的指标(如CPU使用率、内存使用量)和触发告警的条件。
- AI聊天与报告: 点击界面右下角浮动的"Soul"图标,可以打开与LLM的聊天界面。您可以询问关于设备状态、网络健康、统计数据的问题,LLM将通过MCP调用AINFRA的数据和工具来回答您的问题或生成报告。
信息
分类
开发者工具