docker
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package stress
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -18,8 +17,10 @@ type Metric struct {
|
||||
DisableReason string // 禁用时展示的原因
|
||||
}
|
||||
|
||||
// BuildMetrics 根据配置和可用工具,生成要执行的指标列表
|
||||
func BuildMetrics(types []TestType, tools ToolSet) []Metric {
|
||||
// BuildMetrics 根据测试类型生成要执行的指标列表。
|
||||
// 压测工具全部预装在 Docker 镜像中(stress-ng/fio/stressapptest/lm-sensors),
|
||||
// 无需在宿主机检测工具可用性。
|
||||
func BuildMetrics(types []TestType) []Metric {
|
||||
var metrics []Metric
|
||||
|
||||
for _, t := range types {
|
||||
@@ -30,15 +31,7 @@ func BuildMetrics(types []TestType, tools ToolSet) []Metric {
|
||||
case TestMemory:
|
||||
m.Tool = "stress-ng"
|
||||
case TestDiskIO:
|
||||
// disk 优先 fio;无 fio 可降级 stress-ng
|
||||
switch {
|
||||
case tools.Has("fio"):
|
||||
m.Tool = "fio"
|
||||
case tools.Has("stress-ng"):
|
||||
m.Tool = "stress-ng"
|
||||
default:
|
||||
m.Tool = "fio"
|
||||
}
|
||||
m.Tool = "fio"
|
||||
case TestMemNative:
|
||||
m.Tool = "stressapptest"
|
||||
case TestFull:
|
||||
@@ -47,25 +40,11 @@ func BuildMetrics(types []TestType, tools ToolSet) []Metric {
|
||||
m.Enabled = false
|
||||
m.DisableReason = "未知测试类型"
|
||||
}
|
||||
|
||||
// 根据工具可用性决定是否禁用,并记录原因
|
||||
switch t {
|
||||
case TestDiskIO:
|
||||
if !tools.Has("fio") && !tools.Has("stress-ng") {
|
||||
m.Enabled = false
|
||||
m.DisableReason = "缺少 fio 或 stress-ng"
|
||||
}
|
||||
default:
|
||||
if m.Tool != "" && !tools.Has(m.Tool) {
|
||||
m.Enabled = false
|
||||
m.DisableReason = fmt.Sprintf("缺少 %s", m.Tool)
|
||||
}
|
||||
}
|
||||
metrics = append(metrics, m)
|
||||
}
|
||||
|
||||
// 自动附加监控指标
|
||||
metrics = append(metrics, Metric{Name: "temp", Tool: "lm-sensors", Enabled: tools.Has("lm-sensors"), IsMonitor: true})
|
||||
// 自动附加监控指标(容器内执行)
|
||||
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
|
||||
@@ -77,6 +56,7 @@ func BuildMetrics(types []TestType, tools ToolSet) []Metric {
|
||||
|
||||
// Config 压力测试配置
|
||||
type Config struct {
|
||||
Types string // 测试类型(逗号分隔),如 "cpu,memory,disk"
|
||||
Duration time.Duration
|
||||
Threads int
|
||||
MemSizeMB int // 0=自动(可用60%)
|
||||
@@ -84,7 +64,10 @@ type Config struct {
|
||||
DiskDir string // 空=自动临时目录
|
||||
TempLogInt time.Duration
|
||||
TempLimit float64 // 温度上限(°C),0=不判定
|
||||
UseMirror bool // 在线安装时切换国内镜像源(清华TUNA)
|
||||
// 压测统一在 Docker 容器中执行(工具预装在镜像里)
|
||||
DockerImage string // 压测镜像名称,如 stress-test:latest
|
||||
DockerTar string // 本地导出的镜像文件(docker save),目标机无镜像时上传并 load
|
||||
DockerArgs string // Docker 运行参数,如 "--network=host --privileged"
|
||||
}
|
||||
|
||||
// DefaultConfig 默认配置
|
||||
|
||||
Reference in New Issue
Block a user