From 49478e0af5ade56cb54e33a9988bdb6efa655347 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Sun, 7 Dec 2025 18:21:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=A6=82?= =?UTF-8?q?=E8=BF=B0README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 239 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 239 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..bc2ba2b --- /dev/null +++ b/README.md @@ -0,0 +1,239 @@ +# 系统监控平台 + +一个基于Go语言开发的跨平台系统监控工具,支持Linux和Windows操作系统,提供实时的系统性能监控和数据可视化功能。 + +## 功能特性 + +### 监控代理(Agent) +- **跨平台支持**:Linux和Windows操作系统 +- **系统资源监控**: + - CPU使用率和负载 + - 内存使用情况 + - 磁盘空间和I/O + - 网络流量和连接 +- **进程管理**:实时进程列表和资源消耗 +- **硬件信息**:CPU型号、内存大小、磁盘详情、网络接口 +- **操作系统信息**:版本、架构、完整名称 +- **HTTP API**:提供本地数据查询接口 + +### 后端服务(Backend) +- **数据收集**:接收Agent上报的监控数据 +- **数据存储**:支持InfluxDB和MySQL数据库 +- **Web界面**:实时监控仪表盘 +- **图表可视化**:系统资源趋势图 +- **设备管理**:多设备监控和管理 +- **API接口**:提供数据查询和管理接口 + +## 系统架构 + +``` +┌─────────────────┐ ┌─────────────────┐ +│ Linux Agent │──────▶│ │ +└─────────────────┘ │ │ + │ Backend Server │ +┌─────────────────┐ │ │ +│ Windows Agent │──────▶│ │ +└─────────────────┘ └─────────────────┘ + │ + ▼ +┌─────────────────┐ ┌─────────────────┐ +│ InfluxDB │◀──────│ Web Console │ +└─────────────────┘ └─────────────────┘ + │ + ▼ +┌─────────────────┐ +│ MySQL │ +└─────────────────┘ +``` + +## 安装部署 + +### 环境要求 +- Go 1.24+(用于编译) +- InfluxDB 2.x(用于时序数据存储) +- MySQL 8.x(用于设备和配置存储) + +### 编译Agent + +#### Linux Agent +```bash +cd /root/monitor/agent +go build -o agent main.go +``` + +#### Windows Agent +```bash +cd /root/monitor/agent-windows +go build -o agent-windows.exe main.go +# 或使用交叉编译 +GOOS=windows GOARCH=amd64 go build -o agent-windows.exe main.go +``` + +### 编译Backend +```bash +cd /root/monitor/backend +go build -o monitor-server main.go +``` + +### 运行 + +#### Agent运行 + +**Linux**: +```bash +./agent -server=http://your-backend-server:8080 -interval=10s +``` + +**Windows**: +```bash +agent-windows.exe -server=http://your-backend-server:8080 -interval=10s +``` + +#### Backend运行 +```bash +./monitor-server -config=config.json +``` + +## 使用说明 + +### Web界面访问 +访问 `http://your-backend-server:8080` 即可进入监控系统Web界面。 + +### Agent API接口 + +#### 获取系统指标 +```bash +curl http://agent-host:8081/metrics +``` + +#### 获取设备信息 +```bash +curl http://agent-host:8081/info +``` + +#### 获取进程列表 +```bash +curl http://agent-host:8081/processes +``` + +## 配置说明 + +### Agent配置 + +Agent支持通过命令行参数配置: + +``` +-server # 后端服务器地址 +-interval # 数据上报间隔 +-port # 本地API服务端口(默认8081) +-log-level # 日志级别(debug, info, warn, error) +``` + +### Backend配置 + +Backend使用config.json配置文件: + +```json +{ + "server": { + "port": 8080, + "host": "0.0.0.0" + }, + "influxdb": { + "url": "http://localhost:8086", + "token": "your-token", + "org": "monitor", + "bucket": "metrics" + }, + "mysql": { + "host": "localhost", + "port": 3306, + "user": "root", + "password": "password", + "database": "monitor" + } +} +``` + +## 项目结构 + +``` +monitor/ +├── agent/ # Linux监控代理 +│ ├── main.go # 主程序 +│ ├── go.mod # 依赖管理 +│ └── agent # 编译后的可执行文件 +├── agent-windows/ # Windows监控代理 +│ ├── main.go # 主程序 +│ ├── go.mod # 依赖管理 +│ └── agent-windows.exe # 编译后的可执行文件 +└── backend/ # 后端服务 + ├── main.go # 主程序 + ├── config/ # 配置模块 + ├── internal/ # 内部模块 + ├── static/ # Web静态文件 + └── monitor-server # 编译后的可执行文件 +``` + +## API文档 + +### Agent API + +#### GET /metrics +返回系统监控指标,包括CPU、内存、磁盘、网络等信息。 + +#### GET /info +返回设备硬件和操作系统信息。 + +#### GET /processes +返回当前运行的进程列表。 + +### Backend API + +#### POST /api/v1/metrics +接收Agent上报的监控数据。 + +#### GET /api/v1/metrics/:device_id +获取指定设备的历史监控数据。 + +#### GET /api/v1/devices +获取所有注册设备列表。 + +## 开发计划 + +### 已实现功能 +- ✅ 跨平台Agent(Linux/Windows) +- ✅ 系统资源监控 +- ✅ 硬件信息采集 +- ✅ 进程监控 +- ✅ HTTP API接口 +- ✅ Web界面可视化 +- ✅ 数据持久化存储 + +### 后期实现 +- [ ] **告警系统**:基于阈值的系统告警 + - CPU/内存/磁盘使用率告警 + - 网络流量异常告警 + - 进程异常告警 + - 告警通知(邮件、短信、Webhook) +- [ ] 历史数据查询和分析 +- [ ] 多用户权限管理 +- [ ] 集群监控支持 +- [ ] 容器监控集成 +- [ ] 数据导出和报表功能 + +## 技术栈 + +- **语言**:Go 1.24+ +- **Web框架**:原生http包 +- **数据库**:InfluxDB 2.x, MySQL 8.x +- **前端**:HTML, CSS, JavaScript, Chart.js +- **依赖管理**:Go Modules + +## 贡献 + +欢迎提交Issue和Pull Request! + +## 许可证 + +MIT License