Files
membank/auto-check/pkg/stress/metrics.go
张威33321 a8fa159f0f chore: 同步本地更改
- 新增 aio-mcp 项目框架
- 新增 .trae/skills/ OCR/SKU 设计工具
- 更新 auto-check 配置和 stress 包
- 删除 fnhelp 文档目录
- 更新 Docker 压力测试脚本
2026-08-27 20:38:13 +08:00

86 lines
2.6 KiB
Go
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.
package stress
import (
"time"
)
// ============================
// 测试指标定义
// ============================
// Metric 测试指标(定义测什么、用什么工具、怎么判结果)
type Metric struct {
Name string // 指标名称cpu/memory/disk/memnative/full
Tool string // 依赖的工具stress-ng/stressapptest/fio
Enabled bool // 是否启用
IsMonitor bool // 是否为监控指标temp/dmesg自动附加
DisableReason string // 禁用时展示的原因
}
// BuildMetrics 根据测试类型生成要执行的指标列表。
// 压测工具全部预装在 Docker 镜像中stress-ng/fio/stressapptest/lm-sensors
// 无需在宿主机检测工具可用性。
func BuildMetrics(types []TestType) []Metric {
var metrics []Metric
for _, t := range types {
m := Metric{Name: string(t), Enabled: true}
switch t {
case TestCPU:
m.Tool = "stress-ng"
case TestMemory:
m.Tool = "stress-ng"
case TestDiskIO:
m.Tool = "fio"
case TestMemNative:
m.Tool = "stressapptest"
case TestFull:
m.Tool = "stress-ng"
case TestFnStable:
m.Tool = "fnscript"
default:
m.Enabled = false
m.DisableReason = "未知测试类型"
}
metrics = append(metrics, m)
}
// 自动附加监控指标(容器内执行)
metrics = append(metrics, Metric{Name: "temp", Tool: "lm-sensors", Enabled: true, IsMonitor: true})
metrics = append(metrics, Metric{Name: "dmesg", Tool: "", Enabled: true, IsMonitor: true})
return metrics
}
// ============================
// 压力测试配置
// ============================
// Config 压力测试配置
type Config struct {
Types string // 测试类型(逗号分隔),如 "cpu,memory,disk"
Duration time.Duration
Threads int
MemSizeMB int // 0=自动(可用60%)
DiskSizeMB int // 0=默认1024
DiskDir string // 空=自动临时目录
TempLogInt time.Duration
TempLimit float64 // 温度上限(°C)0=不判定
FnMemory bool // fnstable 门禁是否执行 memtester 内存校验30-120 分钟)
// 压测统一在 Docker 容器中执行(工具预装在镜像里)
DockerImage string // 压测镜像名称,如 stress-test:20260824-153045由 build.sh 自动维护)
DockerTar string // 本地导出的镜像文件docker save目标机无镜像时上传并 load
DockerArgs string // Docker 运行参数,如 "--network=host --privileged"
}
// DefaultConfig 默认配置
func DefaultConfig() Config {
return Config{
Duration: 30 * time.Second,
Threads: 4,
DiskSizeMB: 1024,
TempLogInt: 10 * time.Second,
TempLimit: 90,
}
}