Files
Pulse/internal/unifiedresources/host_disk_temperatures.go
rcourtman ac631eadb8 Alert on the Unraid temperature an agent disk shows
A host agent's disk can show a temperature only its Unraid inventory
reports: a SMART row whose smartctl probe returned none takes its
Unraid row's reading, and a disk only the inventory lists is built from
that row alone. The Physical Disks Temp cell, the Running Hot verdict
and Patrol judge that reading against the alert disk temperature
policy, but CheckHost read only the SMART row's own field, so a disk
could read as at its alert threshold while no alert fired.

unifiedresources.HostDiskTemperatureReadings now lists the reading each
of a host's disks shows, built with the registry's own adapters: one
per SMART row, then one per Unraid row whose disk key no SMART row
carries (the history writer's rule). CheckHost judges those. SMART rows
keep their alert resource IDs, an inventory-only disk uses its block
device token, and per-type thresholds follow the disk type the disk
shows. Only a reading collected now fires or resolves, so spun-down
disks hold their alerts. When conflicting serials put two disks on one
device, its alert judges the reading that stands highest against its
own type's threshold.

An inventory-only disk the agent's --disk-exclude patterns match raises
nothing, and an alert it raised before the exclusion resolves on the
next report, as the documented exclusion from monitoring already
suppresses linked Proxmox health and wear alerts. Absence cleanup still
runs only on a non-empty SMART list.

Unraid's own disk temperature notifications do not make this
redundant: Pulse already alerts on the smartctl readings and array
state of the same hosts, which Unraid also notifies on.
2026-10-07 17:32:08 +01:00

98 lines
3.9 KiB
Go

package unifiedresources
import (
"github.com/rcourtman/pulse-go-rewrite/internal/models"
"github.com/rcourtman/pulse-go-rewrite/pkg/diskinventory"
"github.com/rcourtman/pulse-go-rewrite/pkg/fsfilters"
)
// HostDiskTemperatureReading is the temperature one physical disk of a host
// agent shows, taken from the disk resource the registry builds for it.
type HostDiskTemperatureReading struct {
// Device names the disk on the host: a SMART row's device label, or the
// kernel block device token of an Unraid inventory row.
Device string
// MetricID is the disk's history key (HostSMARTDiskMetricID or
// HostUnraidDiskMetricID).
MetricID string
Model string
DiskType string
Temperature int
Collection *diskinventory.CollectionStatus
// Standby reports a SMART row the agent marked as in standby.
Standby bool
// UnraidOnly reports a disk built from the host's Unraid inventory row
// alone, because no SMART row of the host carries its disk key.
UnraidOnly bool
}
// Collected reports whether the reading is a temperature collected now: not
// a disk in standby, and not a reading its collection state marks as kept
// from earlier (diskinventory.TemperatureCollected).
func (r HostDiskTemperatureReading) Collected() bool {
return !r.Standby && diskinventory.TemperatureCollected(r.Temperature, r.Collection)
}
// HostDiskTemperatureReadings returns the temperature each physical disk of a
// host agent shows, in report order: one reading per SMART row the registry
// ingests, then one per Unraid inventory row whose disk key no SMART row of
// the host carries. The registry merges a SMART row and an Unraid row with
// one key into one disk whatever device labels they use, as a controller
// member ("0 [megaraid,0]") and its Unraid device ("sda") do. A SMART row
// without a reading of its own shows the one its Unraid row reports
// (HostSMARTDiskTemperature), and a disk only the Unraid inventory lists, such
// as a --disk-exclude match, shows that row's (HostUnraidDiskTemperature).
// When smartctl and Unraid report different usable serials for one device the
// registry shows both disks, so both are listed. The readings come from the
// adapters the registry builds the disks with, so a consumer judging them
// judges the temperature, collection state and disk type each row's disk
// shows.
func HostDiskTemperatureReadings(host models.Host) []HostDiskTemperatureReading {
readings := make([]HostDiskTemperatureReading, 0, len(host.Sensors.SMART))
smartKeys := make(map[string]struct{}, len(host.Sensors.SMART))
for _, disk := range host.Sensors.SMART {
// The registry ingests no disk for a virtual block device.
if fsfilters.IsVirtualBlockDevice(disk.Device) {
continue
}
key := HostSMARTDiskMetricID(host, disk)
if key != "" {
smartKeys[key] = struct{}{}
}
resource, _ := resourceFromHostSMARTDisk(host, disk)
reading := hostDiskTemperatureReading(disk.Device, key, resource)
reading.Standby = disk.Standby
readings = append(readings, reading)
}
if host.Unraid == nil {
return readings
}
for _, disk := range host.Unraid.Disks {
// HostUnraidDiskMetricID is empty for a row without a device, which
// the registry ingests no disk for.
key := HostUnraidDiskMetricID(host, disk)
if key == "" {
continue
}
if _, ok := smartKeys[key]; ok {
continue
}
resource, _ := resourceFromHostUnraidPhysicalDisk(host, disk)
reading := hostDiskTemperatureReading(normalizePhysicalDiskDeviceToken(disk.Device), key, resource)
reading.UnraidOnly = true
readings = append(readings, reading)
}
return readings
}
func hostDiskTemperatureReading(device, metricID string, resource Resource) HostDiskTemperatureReading {
reading := HostDiskTemperatureReading{Device: device, MetricID: metricID}
if disk := resource.PhysicalDisk; disk != nil {
reading.Model = disk.Model
reading.DiskType = disk.DiskType
reading.Temperature = disk.Temperature
reading.Collection = diskinventory.CloneStatus(disk.Collection)
}
return reading
}