Files
pc-monitor/README.md
2026-05-17 01:47:49 +08:00

155 lines
3.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# PC Monitor - Windows 电脑监控系统
一个用于监控 Windows 电脑硬件状态的系统,支持监控 CPU、GPU、内存、网络、磁盘和电源等信息。
## 系统架构
- **客户端**: Windows 可执行文件 (.exe),负责采集硬件指标数据
- **服务端**: Go 后端 + SQLite 数据库,负责数据存储和 API 服务
- **前端**: Vue 3 + Element Plus Web 仪表盘,负责数据展示
- **部署**: 服务端支持 Docker 一键部署
## 快速开始
### 服务端部署 (Docker)
1. 构建并启动服务端:
```bash
docker-compose up -d
```
2. 访问 Web 仪表盘http://localhost:8080
### 客户端安装 (Windows)
1. 下载客户端可执行文件
2. 编辑 `config.yaml` 配置文件,设置服务器地址
3. 运行客户端:
```powershell
.\pc-monitor-client.exe
```
或者安装为 Windows 服务(开机自启):
```powershell
.\install\install.ps1 -ServerUrl "http://your-server:8080"
```
## 开发环境
### 环境要求
- Go 1.21+
- Node.js 18+
- Docker可选用于部署服务端
### 编译服务端
```bash
cd server
go mod tidy
go build -o server .
```
### 编译客户端
```bash
cd client
go mod tidy
go build -o pc-monitor-client.exe .
```
### 编译前端
```bash
cd web
npm install
npm run build
```
## API 接口
### 设备管理
- `POST /api/v1/register` - 注册新设备
- `GET /api/v1/devices` - 获取设备列表
- `GET /api/v1/devices/:id` - 获取设备详情
- `DELETE /api/v1/devices/:id` - 删除设备
- `POST /api/v1/devices/:id/heartbeat` - 设备心跳
### 指标数据
- `POST /api/v1/report` - 上报指标数据
- `GET /api/v1/devices/:id/metrics/latest` - 获取最新指标
- `GET /api/v1/devices/:id/metrics/history` - 获取历史指标
### 告警管理
- `GET /api/v1/alerts` - 获取活跃告警列表
- `POST /api/v1/alerts/rules` - 创建告警规则
- `GET /api/v1/devices/:id/alerts/rules` - 获取设备告警规则
- `DELETE /api/v1/alerts/rules/:id` - 删除告警规则
- `POST /api/v1/alerts/:id/resolve` - 解决告警
## 配置说明
### 服务端配置 (config.yaml)
```yaml
server:
addr: ":8080" # 监听地址
database:
path: "./data/monitor.db" # 数据库路径
retention_days: 30 # 数据保留天数
auth:
admin_password: "admin123" # 管理密码
```
### 客户端配置 (config.yaml)
```yaml
server:
url: "http://your-server:8080" # 服务器地址
token: "" # 设备令牌(首次注册后自动生成)
collect:
interval: 30s # 数据采集间隔
report:
interval: 60s # 数据上报间隔
```
## 监控指标
| 模块 | 监控内容 |
|------|----------|
| CPU | 使用率、温度、每核使用率 |
| 内存 | 总量、已用、使用率 |
| GPU | 使用率、温度、显存(支持 NVIDIA |
| 磁盘 | 各分区容量、已用空间、使用率 |
| 网络 | 网卡状态、IP 地址、收发流量 |
| 电源 | 电池状态、电量百分比、充电状态 |
## 项目结构
```
pc-monitor/
├── client/ # Windows 客户端
│ ├── collector/ # 数据采集模块
│ ├── reporter/ # 数据上报模块
│ └── install/ # 安装脚本
├── server/ # 服务端
│ ├── api/ # API 路由和处理器
│ ├── model/ # 数据模型
│ ├── service/ # 业务逻辑
│ └── repository/ # 数据访问层
├── web/ # 前端源码
│ └── src/
│ ├── views/ # 页面组件
│ └── api/ # API 调用封装
├── docker-compose.yml # Docker 部署配置
└── Dockerfile.server # 服务端镜像构建
```
## 许可证
MIT License