mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-23 20:25:56 +00:00
Colour report disk temperatures by the alert thresholds
The PDF performance report's disk table coloured a temperature amber from 50C and red from 60C for every disk type, the last fixed disk heat line after disk heat moved to the alert disk temperature policy. An NVMe at 63C, well under its 70C alert trigger, printed red. A user's raised trigger changed nothing. Each reported disk now carries the tenant's alert thresholds for its type (the clear value and the trigger, from alerts.Manager.DiskTemperatureThreshold). The PDF colours the reading amber from the clear value and red from the trigger, as the Physical Disks Temp column does, and leaves it plain when disk temperature alerting is off.
This commit is contained in:
+20
-2
@@ -1670,9 +1670,10 @@ func (g *PDFGenerator) writeDisksSection(pdf *fpdf.Fpdf, data *ReportData) {
|
||||
tempStr := "-"
|
||||
if disk.Temperature > 0 {
|
||||
tempStr = fmt.Sprintf("%dC", disk.Temperature)
|
||||
if disk.Temperature >= 60 {
|
||||
switch diskTemperatureSeverity(disk) {
|
||||
case "critical":
|
||||
pdf.SetTextColor(colorDanger[0], colorDanger[1], colorDanger[2])
|
||||
} else if disk.Temperature >= 50 {
|
||||
case "warning":
|
||||
pdf.SetTextColor(colorWarning[0], colorWarning[1], colorWarning[2])
|
||||
}
|
||||
}
|
||||
@@ -2808,3 +2809,20 @@ func formatDuration(d time.Duration) string {
|
||||
}
|
||||
return fmt.Sprintf("%d %s", minutes, minWord)
|
||||
}
|
||||
|
||||
// diskTemperatureSeverity colours a disk reading by its alert disk temperature
|
||||
// thresholds: "critical" from the trigger, "warning" from the clear value, and
|
||||
// "" below it or when the disk carries no thresholds.
|
||||
func diskTemperatureSeverity(disk DiskInfo) string {
|
||||
if disk.Temperature <= 0 || disk.TemperatureCritical <= 0 {
|
||||
return ""
|
||||
}
|
||||
reading := float64(disk.Temperature)
|
||||
if reading >= disk.TemperatureCritical {
|
||||
return "critical"
|
||||
}
|
||||
if disk.TemperatureWarning > 0 && reading >= disk.TemperatureWarning {
|
||||
return "warning"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -57,3 +57,26 @@ func TestFormatDuration(t *testing.T) {
|
||||
t.Fatalf("expected 2 days, 1 hour, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// Disk temperatures in a report take the disk's alert thresholds, not a fixed
|
||||
// 50/60C: an NVMe at 63C under a 70C trigger stays uncoloured, a SATA disk at
|
||||
// 56C past its 55C trigger is red, and a disk without thresholds is plain.
|
||||
func TestDiskTemperatureSeverityFollowsAlertThresholds(t *testing.T) {
|
||||
cases := []struct {
|
||||
disk DiskInfo
|
||||
want string
|
||||
}{
|
||||
{DiskInfo{Temperature: 63, TemperatureWarning: 65, TemperatureCritical: 70}, ""},
|
||||
{DiskInfo{Temperature: 66, TemperatureWarning: 65, TemperatureCritical: 70}, "warning"},
|
||||
{DiskInfo{Temperature: 70, TemperatureWarning: 65, TemperatureCritical: 70}, "critical"},
|
||||
{DiskInfo{Temperature: 56, TemperatureWarning: 50, TemperatureCritical: 55}, "critical"},
|
||||
{DiskInfo{Temperature: 72, TemperatureWarning: 70, TemperatureCritical: 75}, "warning"},
|
||||
{DiskInfo{Temperature: 80}, ""},
|
||||
{DiskInfo{Temperature: 0, TemperatureWarning: 50, TemperatureCritical: 55}, ""},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
if got := diskTemperatureSeverity(tc.disk); got != tc.want {
|
||||
t.Errorf("diskTemperatureSeverity(%+v) = %q, want %q", tc.disk, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,6 +153,12 @@ type DiskInfo struct {
|
||||
Health string // PASSED, FAILED, UNKNOWN
|
||||
Temperature int // Celsius
|
||||
WearLevel int // 0-100, percentage of life REMAINING (100 = healthy, 0 = end of life, -1 = unknown)
|
||||
// TemperatureWarning and TemperatureCritical are the disk's alert disk
|
||||
// temperature thresholds in Celsius (the clear value and the trigger). The
|
||||
// reading is amber from Warning and red from Critical, as in the Physical
|
||||
// Disks Temp column. A zero Critical leaves the reading uncoloured.
|
||||
TemperatureWarning float64
|
||||
TemperatureCritical float64
|
||||
}
|
||||
|
||||
// MultiReportRequest defines the parameters for generating a multi-resource report.
|
||||
|
||||
Reference in New Issue
Block a user