Fix NVMe self-tests and mobile layout
This commit is contained in:
37
disks.go
37
disks.go
@@ -391,6 +391,17 @@ type smartctlJSON struct {
|
||||
} `json:"table"`
|
||||
} `json:"standard"`
|
||||
} `json:"ata_smart_self_test_log"`
|
||||
NVMeSelfTestLog struct {
|
||||
Table []struct {
|
||||
SelfTestCode struct {
|
||||
String string `json:"string"`
|
||||
} `json:"self_test_code"`
|
||||
SelfTestResult struct {
|
||||
String string `json:"string"`
|
||||
} `json:"self_test_result"`
|
||||
PowerOnHours uint64 `json:"power_on_hours"`
|
||||
} `json:"table"`
|
||||
} `json:"nvme_self_test_log"`
|
||||
NVMeHealth *struct {
|
||||
Temperature float64 `json:"temperature"`
|
||||
PercentageUsed float64 `json:"percentage_used"`
|
||||
@@ -410,6 +421,10 @@ func applySMART(disk *DiskMetrics) {
|
||||
if len(output) == 0 {
|
||||
return
|
||||
}
|
||||
applySMARTJSON(disk, output)
|
||||
}
|
||||
|
||||
func applySMARTJSON(disk *DiskMetrics, output []byte) {
|
||||
var smart smartctlJSON
|
||||
if json.Unmarshal(output, &smart) != nil {
|
||||
return
|
||||
@@ -451,12 +466,20 @@ func applySMART(disk *DiskMetrics) {
|
||||
disk.AttentionReasons = append(disk.AttentionReasons, "Ошибки целостности носителя: "+strconv.FormatUint(smart.NVMeHealth.MediaErrors, 10))
|
||||
}
|
||||
}
|
||||
if len(smart.ATASelfTestLog.Standard.Table) > 0 {
|
||||
if len(smart.NVMeSelfTestLog.Table) > 0 {
|
||||
last := smart.NVMeSelfTestLog.Table[0]
|
||||
description := strings.TrimSpace(last.SelfTestCode.String)
|
||||
result := firstNonEmpty(strings.TrimSpace(last.SelfTestResult.String), "Результат неизвестен")
|
||||
if description != "" {
|
||||
disk.LastSelfTest = description + " · " + result
|
||||
} else {
|
||||
disk.LastSelfTest = result
|
||||
}
|
||||
setLastSelfTestAt(disk, last.PowerOnHours)
|
||||
} else if len(smart.ATASelfTestLog.Standard.Table) > 0 {
|
||||
last := smart.ATASelfTestLog.Standard.Table[0]
|
||||
disk.LastSelfTest = firstNonEmpty(last.Status.String, "Результат неизвестен")
|
||||
if disk.PowerOnHours != nil && *disk.PowerOnHours >= last.LifetimeHours {
|
||||
disk.LastSelfTestAt = time.Now().Add(-time.Duration(*disk.PowerOnHours-last.LifetimeHours) * time.Hour).Format(time.RFC3339)
|
||||
}
|
||||
setLastSelfTestAt(disk, last.LifetimeHours)
|
||||
} else {
|
||||
disk.SelfTestNeverRun = true
|
||||
disk.LastSelfTest = "Никогда не запускался"
|
||||
@@ -469,6 +492,12 @@ func applySMART(disk *DiskMetrics) {
|
||||
}
|
||||
}
|
||||
|
||||
func setLastSelfTestAt(disk *DiskMetrics, testPowerOnHours uint64) {
|
||||
if disk.PowerOnHours != nil && *disk.PowerOnHours >= testPowerOnHours {
|
||||
disk.LastSelfTestAt = time.Now().Add(-time.Duration(*disk.PowerOnHours-testPowerOnHours) * time.Hour).Format(time.RFC3339)
|
||||
}
|
||||
}
|
||||
|
||||
func applyATAAttributes(disk *DiskMetrics, smart smartctlJSON) {
|
||||
wearNames := map[string]bool{
|
||||
"Percent_Lifetime_Remain": true, "SSD_Life_Left": true,
|
||||
|
||||
Reference in New Issue
Block a user