重构 auto-check:状态数据下沉各包,workflow 精简为纯调度
- discovery: ping 探测存活 + ARP 解析 MAC,包级 Devices map,串行扫描 - stress: 脚本生成模式(BuildScript/ParseResults),ToolSet 工具检测,包级 Results map - report: 包级 Printed map,SaveAndPrintDeviceReport 保存+打印 - sshclient: 包级 RunCommand - workflow: 仅持有 config,Start() 固定循环,直接调用各包方法 - config: 移除 ScanConfig.Concurrency(串行扫描无需并发数)
This commit is contained in:
74
auto-check/pkg/stress/metrics.go
Normal file
74
auto-check/pkg/stress/metrics.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package stress
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ============================
|
||||
// 测试指标定义
|
||||
// ============================
|
||||
|
||||
// Metric 测试指标(定义测什么、用什么工具、怎么判结果)
|
||||
type Metric struct {
|
||||
Name string // 指标名称(cpu/memory/disk/memnative/full)
|
||||
Tool string // 依赖的工具(stress-ng/stressapptest)
|
||||
Enabled bool // 是否启用
|
||||
IsMonitor bool // 是否为监控指标(temp/dmesg,自动附加)
|
||||
}
|
||||
|
||||
// BuildMetrics 根据配置和可用工具,生成要执行的指标列表
|
||||
func BuildMetrics(types []TestType, tools ToolSet) []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 = "stress-ng"
|
||||
case TestMemNative:
|
||||
m.Tool = "stressapptest"
|
||||
case TestFull:
|
||||
m.Tool = "stress-ng"
|
||||
default:
|
||||
m.Enabled = false
|
||||
}
|
||||
if m.Tool != "" && !tools.Has(m.Tool) {
|
||||
m.Enabled = false // 工具不可用,禁用
|
||||
}
|
||||
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: "dmesg", Tool: "", Enabled: true, IsMonitor: true})
|
||||
|
||||
return metrics
|
||||
}
|
||||
|
||||
// ============================
|
||||
// 压力测试配置
|
||||
// ============================
|
||||
|
||||
// Config 压力测试配置
|
||||
type Config struct {
|
||||
Duration time.Duration
|
||||
Threads int
|
||||
MemSizeMB int // 0=自动(可用60%)
|
||||
DiskSizeMB int // 0=默认1024
|
||||
DiskDir string // 空=自动临时目录
|
||||
TempLogInt time.Duration // 0=10s
|
||||
}
|
||||
|
||||
// DefaultConfig 默认配置
|
||||
func DefaultConfig() Config {
|
||||
return Config{
|
||||
Duration: 30 * time.Second,
|
||||
Threads: 4,
|
||||
DiskSizeMB: 1024,
|
||||
TempLogInt: 10 * time.Second,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user