Files
membank/auto-check/docker/stress-test/README.md
12600k-rog-d4 b673ed62f9 docker
2026-08-24 00:35:30 +08:00

100 lines
3.7 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.
# stress-test 镜像
压力测试镜像,为 auto-check 提供预装压测工具与测试脚本的容器环境。压测统一在容器内执行,无需在目标机在线安装任何依赖。
## 工作流程
```
┌─────────────────────────────────────────────────────────────┐
│ auto-check 工作流程 │
│ │
│ 1. 检测目标机器的 Docker 可用性 │
│ 2. 检查镜像是否存在(不存在则上传本地导出的 tar 并 docker load
│ 3. 启动容器执行测试(脚本已打包在镜像中) │
│ 4. 收集测试结果并解析 │
│ 5. 生成报告 │
└─────────────────────────────────────────────────────────────┘
```
## 优势
| 特性 | 说明 |
|------|------|
| 工具获取 | 预装在镜像中,无需在线安装 |
| 网络依赖 | 镜像已缓存后目标机无需联网 |
| 环境一致性 | 统一的容器环境,不受目标机发行版差异影响 |
## 构建与导出(维护时使用)
固定分发模式:不依赖 registry镜像以 tar 文件形式放在工程目录,
目标机无镜像时由 auto-check 自动上传并 `docker load`
```bash
cd docker/stress-test
docker build -t stress-test:latest .
# 导出到工程目录(供 auto-check 上传分发,已加入 .gitignore
docker save -o stress-test.tar stress-test:latest
```
## 使用
`auto-check.yaml` 中配置:
```yaml
stress:
docker_image: "stress-test:latest"
docker_tar: "docker/stress-test/stress-test.tar"
docker_args: "--network=host --privileged"
```
## 环境变量
容器运行时通过以下环境变量传入参数:
| 变量 | 说明 | 默认值 |
|------|------|--------|
| `AUTOCHECK_TYPES` | 测试类型(逗号分隔) | `cpu,memory` |
| `AUTOCHECK_DURATION` | 持续时间(秒) | `30` |
| `AUTOCHECK_THREADS` | 线程数 | `4` |
| `AUTOCHECK_MEM_SIZE_MB` | 内存压测大小 | `0` (自动) |
| `AUTOCHECK_DISK_SIZE_MB` | 磁盘压测大小 | `1024` |
| `AUTOCHECK_DISK_DIR` | 磁盘压测目录 | `/tmp` |
| `AUTOCHECK_TEMP_INTERVAL` | 温度采样间隔 | `10` |
| `AUTOCHECK_SAMPLE_INTERVAL` | 运行时采样间隔 | `2` |
## 容器内执行流程run.sh
1. 系统信息(`===SYSTEM_INFO===`
2. 温度监控后台采样(`temp_start.sh`
3. 各项压测先单项cpu/memory/disk/memnative、综合full最后
4. 温度监控收尾(`===MONITOR:temp===`
5. 内核日志(`===MONITOR:dmesg===`+ 结束标记
## 镜像内容
```
/stress-test/
├── Dockerfile # 镜像定义
├── scripts/ # 测试脚本
│ ├── run.sh # 入口脚本
│ ├── cpu.sh # CPU 压测
│ ├── memory.sh # 内存压测
│ ├── disk.sh # 磁盘压测
│ ├── full.sh # 综合压测
│ ├── memnative.sh # 内存精压
│ ├── sysinfo.sh # 系统信息
│ ├── temp_start.sh # 温度监控启动
│ ├── temp_end.sh # 温度监控收尾
│ └── dmesg.sh # 内核日志
└── README.md # 本文档
```
## 依赖工具
| 工具 | 用途 |
|------|------|
| `stress-ng` | CPU/内存/磁盘压测 |
| `fio` | 磁盘 IO 测试 |
| `lm-sensors` | 温度监控 |
| `sysstat` | 系统性能统计 |
| `procps` | 进程监控 |