117 lines
4.0 KiB
Go
117 lines
4.0 KiB
Go
package model
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// TestBlock 表示单个测试数据块
|
|
type TestBlock struct {
|
|
ID string `json:"id"`
|
|
Data []byte `json:"data"`
|
|
Size int `json:"size"` // 数据块大小(字节)
|
|
Checksum string `json:"checksum"` // SHA-256校验和
|
|
CreatedAt time.Time `json:"created_at"` // 创建时间
|
|
Sequence int `json:"sequence"` // 数据块序列号
|
|
}
|
|
|
|
// NewTestBlock 创建一个新的测试数据块
|
|
func NewTestBlock(data []byte, sequence int) *TestBlock {
|
|
hash := sha256.Sum256(data)
|
|
checksum := hex.EncodeToString(hash[:])
|
|
|
|
return &TestBlock{
|
|
ID: uuid.New().String(),
|
|
Data: data,
|
|
Size: len(data),
|
|
Checksum: checksum,
|
|
CreatedAt: time.Now(),
|
|
Sequence: sequence,
|
|
}
|
|
}
|
|
|
|
// Verify 验证数据块的完整性
|
|
func (tb *TestBlock) Verify() bool {
|
|
hash := sha256.Sum256(tb.Data)
|
|
checksum := hex.EncodeToString(hash[:])
|
|
return checksum == tb.Checksum
|
|
}
|
|
|
|
// TestResult 表示测试结果
|
|
type TestResult struct {
|
|
ID string `json:"id"`
|
|
TestName string `json:"test_name"`
|
|
StartTime time.Time `json:"start_time"`
|
|
EndTime time.Time `json:"end_time"`
|
|
Duration float64 `json:"duration"` // 持续时间(秒)
|
|
BlocksWritten int `json:"blocks_written"`
|
|
BlocksVerified int `json:"blocks_verified"`
|
|
DataWrittenMB float64 `json:"data_written_mb"`
|
|
Success bool `json:"success"`
|
|
Error string `json:"error,omitempty"`
|
|
WriteSpeedMBs float64 `json:"write_speed_mbs"` // MB/s
|
|
Metrics TestMetrics `json:"metrics"`
|
|
}
|
|
|
|
// TestMetrics 包含测试的性能指标
|
|
type TestMetrics struct {
|
|
WriteLatencyMs float64 `json:"write_latency_ms"` // 平均写入延迟(毫秒)
|
|
ReadLatencyMs float64 `json:"read_latency_ms"` // 平均读取延迟(毫秒)
|
|
IOPS float64 `json:"iops"` // 每秒IO操作数
|
|
DataIntegrityLoss int `json:"data_integrity_loss"` // 数据完整性丢失次数
|
|
RecoveryTimeMs float64 `json:"recovery_time_ms"` // 断电后恢复时间(毫秒)
|
|
}
|
|
|
|
// TestRequest 表示客户端发送的测试请求
|
|
type TestRequest struct {
|
|
TestType string `json:"test_type"`
|
|
BlockSize int `json:"block_size"`
|
|
DataSizeMB int `json:"data_size_mb"`
|
|
Concurrency int `json:"concurrency"`
|
|
Parameters map[string]string `json:"parameters"`
|
|
ClientID string `json:"client_id"`
|
|
RequestTime time.Time `json:"request_time"`
|
|
}
|
|
|
|
// TestResponse 表示服务器对测试请求的响应
|
|
type TestResponse struct {
|
|
RequestID string `json:"request_id"`
|
|
Status string `json:"status"` // success, error
|
|
Message string `json:"message,omitempty"`
|
|
Result *TestResult `json:"result,omitempty"`
|
|
ServerTime time.Time `json:"server_time"`
|
|
}
|
|
|
|
// PowerCutInfo 表示断电信息
|
|
type PowerCutInfo struct {
|
|
Timestamp time.Time `json:"timestamp"`
|
|
Duration int `json:"duration"` // 断电持续时间(秒)
|
|
BlocksWritten int `json:"blocks_written"`
|
|
RecoverySuccess bool `json:"recovery_success"`
|
|
DataLossMB float64 `json:"data_loss_mb"`
|
|
}
|
|
|
|
// TestStatus 表示测试状态
|
|
type TestStatus struct {
|
|
TestID string `json:"test_id"`
|
|
TestType string `json:"test_type"`
|
|
Status string `json:"status"` // running, completed, failed
|
|
Progress float64 `json:"progress"` // 0-100%
|
|
StartTime time.Time `json:"start_time"`
|
|
CurrentPhase string `json:"current_phase"`
|
|
Message string `json:"message,omitempty"`
|
|
}
|
|
|
|
// HealthStatus 表示服务器健康状态
|
|
type HealthStatus struct {
|
|
Status string `json:"status"` // ok, error
|
|
Timestamp time.Time `json:"timestamp"`
|
|
DiskSpace float64 `json:"disk_space"`
|
|
CpuUsage float64 `json:"cpu_usage"`
|
|
MemoryUsage float64 `json:"memory_usage"`
|
|
Message string `json:"message,omitempty"`
|
|
}
|