Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Report every lm-sensors temperature and fan with a stable key

rcourtmane31210deecf0
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 5b855d4daf..ca06941653 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -3701,6 +3701,14 @@ unauthenticated bootstrap behavior.
maps warning, critical, and opted-in error states into canonical alerts.
Enabling custom sensors must not imply `agent:exec`, AI command authority, or
any general remote-shell capability.
+ Hardware temperatures and fans the agent already reads through lm-sensors
+ belong in the additive `sensors.native` inventory, not in custom sensors:
+ one entry per `tempN_input`/`fanN_input`, keyed `<chip>/<channel>` with the
+ full chip name, original label, kind, unit, unconverted value and
+ `ok`/`invalid` status, bounded at 256 entries on both sides of the report;
+ the server rebuilds the key check and the status on ingest. It needs no new
+ collector, command, permission or configuration, and an agent that predates
+ it simply omits the field. Cluster peer entries carry no inventory.
Runtime RAID collection uses `/proc/mdstat` as the canonical discovery
baseline for Linux md arrays. `mdadm --detail` may enrich level, state,
member, UUID, and rebuild fields when available, but missing or failing
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 5f257d7ec3..5d8a408447 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -6302,6 +6302,20 @@ Backend API payloads and `frontend-modern/src/types/api.ts` must preserve that
optional map without making it a required compatibility field, and clients must
keep it as descriptive host telemetry rather than a temperature metric,
resource identity, alert metric, or storage/recovery signal.
+Host sensor summaries may also carry the native temperature and fan inventory
+in `native`: `id` (`<chip>/<channel>`), `chip`, optional `adapter`, `channel`,
+`label`, `kind` (`temperature`/`fan`), `unit` (`celsius`/`rpm`), optional
+`value` and `status` (`ok`/`invalid`). The models-backed frontend host
+summary always emits `native` as a possibly empty array, beside `custom` and
+`gpu`; the unified-resource and agent payloads omit it when empty. No
+frontend code reads it yet, so `frontend-modern/src/types/api.ts` gains its
+optional `native` type with the first consumer.
+`id` is the host-scoped sensor source key; `label` is display text and is not
+unique. Clients must not chart, alert on or headline an `invalid` entry, and
+must not read an absent or empty `native` array, or an entry missing from a
+non-empty one, as a host without sensors or a removed sensor: older agents
+omit it, failed collection sends nothing and the inventory is bounded at 256
+entries, so a truncated list can drop an entry that still exists.
Host sensor SMART rows (`smart[]`) also carry the optional per-field
`collection` status (`PhysicalDiskCollectionStatus`). Backend API payloads and
`frontend-modern/src/types/api.ts` (`HostDiskSMART.collection`) must preserve it
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index 6a2b7de514..4dda4b8827 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -228,6 +228,50 @@ complete report from the real parser/agent path. The inferred #3565 sensor
fixture is not an original JSON export or installed-host recovery. Consuming
proof must use the complete emitted report, not a selected-value subset.
+### Native sensor inventory keeps one identity per input
+
+The shared Linux agent parser also reports `sensors.native`: every `tempN_input`
+and `fanN_input` of every chip, keyed `<chip>/<channel>` from the full
+lm-sensors chip name (bus address included) and the canonical channel (`tempN`
+or `fanN`, no leading zeros), with the chip's original feature label, kind,
+unit, unconverted value and an `ok`/`invalid` status. Two chips of one type and
+labels that differ only by case keep separate entries, which the legacy
+`TemperatureCelsius`, `FanRPM` and `Additional` maps cannot do. The key is a
+host-scoped source key, not a physical-device identity: a moved PCI address,
+re-enumerated USB/I²C chip or renumbered channel can change or reuse it, so
+persisted preferences need their own device-binding and migration rules.
+`sensors.NativeSensorStatus` owns plausibility: `ok` needs a finite value, from
+-55 to 150 °C inclusive or at least 0 RPM. Out-of-band values stay listed as
+`invalid`, a non-finite value is omitted, and a stopped fan's 0 RPM is a
+reading. The inventory is sorted by chip, kind and channel, deduplicated by ID
+and bounded at 256 entries; a chip whose inputs leave the legacy maps empty
+still reports its inventory. Ingest keeps an entry only when its ID is exactly
+`<chip>/<channel>` for a canonical channel of the reported kind, derives the
+unit from the kind, recomputes the status with the same policy, keeps the first
+entry of a repeated ID and applies the same 256 bound. A chip with inventory
+only still skips power collection, as before. The legacy maps keep
+their keys, filters and consumers. Cluster peer collection omits the
+inventory, which belongs to each host's own report.
+
+This is the identity foundation for #3565. Nothing reads the inventory yet: it
+adds no alert, threshold, History series, sensor preference, CPU-source choice
+or UI. An absent field (older agent, failed collection), an empty inventory
+and a truncated one are not distinguished, and the 256 bound drops the last
+chips in name order, so no consumer may read a missing entry as a removed
+sensor until the report carries completeness state. When one chip's
+`sensors -j` object repeats a feature label, only the last feature object of
+that label survives decoding. Child alert IDs and
+metric names are lower-cased today, so consumers need a collision-free
+encoding of the ID before using it as a key. `internal/sensors/native.go` owns
+the inventory; `parser_units_test.go`,
+`TestAgentMixedSensorUnitsReachReportWithoutFalseTemperatures`,
+`TestAgentReportsNativeInventoryWithoutLegacyReadings`,
+`TestCollectPeerSensors_OmitsNativeInventory` and
+`TestApplyHostReportPreservesNativeSensorInventory` cover parsing, the agent's
+complete `Sensors` result, peer omission and ingest through the frontend and
+read-state projections. The fixtures are inferred lm-sensors JSON, not exports
+from an installed host.
+
### Background backup scans belong to their configured connection
PVE tasks, storage backups and guest snapshots share one in-flight owner per
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 8a4135a75e..5a8f5888e0 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -4172,6 +4172,12 @@ recovery scope, or a storage/recovery-owned secret source.
disk cache, ZFS ARC sizing, storage-tier health, or capacity-planning
evidence; disk and pool truth stays on the canonical storage and
physical-disk resources.
+ `internal/unifiedresources/types.go` also carries `HostSensorMeta.native`,
+ the agent's lm-sensors temperature and fan inventory. An NVMe or drive-bay
+ entry there is descriptive host context: storage and recovery must keep
+ disk temperature, SMART and disk-heat truth on the physical-disk resources
+ and must not read a native sensor as disk health, protection or recovery
+ evidence. The inventory opens no storage or recovery path.
`internal/unifiedresources/types.go` also carries `AvailabilityData`
(probe protocol, address, latency, failure state) as a resource facet for
agentless monitoring. Storage and recovery must not treat that availability
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index c3ca9191f5..f1772ae7e9 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -2227,6 +2227,19 @@ descriptive host context. Unified-resource consumers must not promote power
sensors into separate hardware resources, lifecycle state, workload identity,
storage health, alert metrics, or history targets without a separate governed
metric contract.
+The native lm-sensors inventory follows that same route.
+`HostSensorMeta.native` carries each temperature and fan input's host-scoped
+`<chip>/<channel>` source key (not a physical-device identity), chip, adapter,
+channel, original label, kind, unit,
+value and `ok`/`invalid` status through `resourceFromHost`, clone and the
+read-state projection back to `models.HostSensorSummary`, with a private slice
+and value pointers. It stays descriptive host context on the agent facet: a
+sensor is not a separate resource, child alert target, operator-posture
+target or history identity until a later governed contract defines its owner
+resolution, Thresholds projection and migration.
+`TestResourceFromHostPreservesNativeSensorInventory` and
+`TestCloneHostSensorMetaIsolatesNativeInventory` cover the adapter and clone
+isolation.
Metric bar fallbacks follow that split as well: unified-resource consumers own
which CPU or memory value is selected, plus any source-specific fallback reason
such as outdated standalone agent telemetry, while platform tables must use
diff --git a/internal/hostagent/agent.go b/internal/hostagent/agent.go
index 1c758867af..4903d8eab1 100644
--- a/internal/hostagent/agent.go
+++ b/internal/hostagent/agent.go
@@ -1894,13 +1894,19 @@ func (a *Agent) collectTemperatures(ctx context.Context) agentshost.Sensors {
return a.collectNVIDIATemperatureSensors(ctx)
}
- if !tempData.Available {
+ // A chip with only a stopped fan or out-of-range inputs leaves the legacy
+ // maps empty but still has an inventory worth reporting.
+ if !tempData.Available && len(tempData.Native) == 0 {
a.logger.Debug().Msg("No temperature sensors available on this system")
return a.collectNVIDIATemperatureSensors(ctx)
}
result := convertTemperatureDataToSensors(tempData)
a.mergeNVIDIATemperatures(ctx, &result)
+ if !tempData.Available {
+ // Inventory only: keep the existing gate on power collection.
+ return result
+ }
// Collect power consumption data (Intel RAPL, etc.)
if powerData, err := a.collector.SensorsPower(ctx); err == nil && powerData != nil && powerData.Available {
@@ -1974,6 +1980,24 @@ func convertTemperatureDataToSensors(tempData *sensors.TemperatureData) agentsho
}
}
+ // Add the full temperature and fan inventory with stable identities.
+ if len(tempData.Native) > 0 {
+ result.Native = make([]agentshost.NativeSensor, len(tempData.Native))
+ for i, sensor := range tempData.Native {
+ result.Native[i] = agentshost.NativeSensor{
+ ID: sensor.ID,
+ Chip: sensor.Chip,
+ Adapter: sensor.Adapter,
+ Channel: sensor.Channel,
+ Label: sensor.Label,
+ Kind: sensor.Kind,
+ Unit: sensor.Unit,
+ Value: sensor.Value,
+ Status: sensor.Status,
+ }
+ }
+ }
+
return result
}
diff --git a/internal/hostagent/agent_sensors_test.go b/internal/hostagent/agent_sensors_test.go
index 0b2fd7fcd7..66fe57a8b3 100644
--- a/internal/hostagent/agent_sensors_test.go
+++ b/internal/hostagent/agent_sensors_test.go
@@ -450,6 +450,19 @@ func TestAgentMixedSensorUnitsReachReportWithoutFalseTemperatures(t *testing.T)
TemperatureCelsius: map[string]float64{"cpu_package": 91, "cpu_core_0": 87, "nvme0": 36.9, "amdgpu-pci-0300_edge": 58},
FanRPM: map[string]float64{"applesmc_left_side": 6152, "applesmc_right_side": 5699},
Additional: map[string]float64{"applesmc_tb0t": 34.2, "applesmc_tb1t": 29.2, "applesmc_th1h": 44.5},
+ Native: []agentshost.NativeSensor{
+ reportNativeSensor("amdgpu-pci-0300", "", "temp1", "edge", agentshost.NativeSensorKindTemperature, 58, agentshost.NativeSensorStatusOK),
+ reportNativeSensor("applesmc-isa-0300", "ISA adapter", "temp1", "TB0T", agentshost.NativeSensorKindTemperature, 34.2, agentshost.NativeSensorStatusOK),
+ reportNativeSensor("applesmc-isa-0300", "ISA adapter", "temp2", "TB1T", agentshost.NativeSensorKindTemperature, 29.2, agentshost.NativeSensorStatusOK),
+ reportNativeSensor("applesmc-isa-0300", "ISA adapter", "temp3", "Th1H", agentshost.NativeSensorKindTemperature, 44.5, agentshost.NativeSensorStatusOK),
+ reportNativeSensor("applesmc-isa-0300", "ISA adapter", "temp4", "TG1D", agentshost.NativeSensorKindTemperature, -127, agentshost.NativeSensorStatusInvalid),
+ reportNativeSensor("applesmc-isa-0300", "ISA adapter", "temp5", "TCMc", agentshost.NativeSensorKindTemperature, 0, agentshost.NativeSensorStatusOK),
+ reportNativeSensor("applesmc-isa-0300", "ISA adapter", "fan1", "Left side", agentshost.NativeSensorKindFan, 6152, agentshost.NativeSensorStatusOK),
+ reportNativeSensor("applesmc-isa-0300", "ISA adapter", "fan2", "Right side", agentshost.NativeSensorKindFan, 5699, agentshost.NativeSensorStatusOK),
+ reportNativeSensor("coretemp-isa-0000", "", "temp1", "Package id 0", agentshost.NativeSensorKindTemperature, 91, agentshost.NativeSensorStatusOK),
+ reportNativeSensor("coretemp-isa-0000", "", "temp2", "Core 0", agentshost.NativeSensorKindTemperature, 87, agentshost.NativeSensorStatusOK),
+ reportNativeSensor("nvme-pci-0200", "", "temp1", "Composite", agentshost.NativeSensorKindTemperature, 36.9, agentshost.NativeSensorStatusOK),
+ },
}
if !reflect.DeepEqual(want, got) {
t.Fatalf("full sensor report = %+v, want %+v", got, want)
@@ -462,3 +475,42 @@ func TestAgentMixedSensorUnitsReachReportWithoutFalseTemperatures(t *testing.T)
t.Log("SENSOR_UNITS_FRAME=" + string(data))
}
}
+
+func reportNativeSensor(chip, adapter, channel, label, kind string, value float64, status string) agentshost.NativeSensor {
+ unit := agentshost.NativeSensorUnitCelsius
+ if kind == agentshost.NativeSensorKindFan {
+ unit = agentshost.NativeSensorUnitRPM
+ }
+ return agentshost.NativeSensor{ID: chip + "/" + channel, Chip: chip, Adapter: adapter, Channel: channel, Label: label,
+ Kind: kind, Unit: unit, Value: &value, Status: status}
+}
+
+func TestAgentReportsNativeInventoryWithoutLegacyReadings(t *testing.T) {
+ // A stopped fan and an unattached input give the legacy maps nothing, so
+ // the parser marks the data unavailable, but the inventory still says
+ // what the chip exposes.
+ mc := &mockCollector{
+ goos: "linux",
+ sensorsLocalFn: func(context.Context) (string, error) {
+ return `{"applesmc-isa-0300":{"Adapter":"ISA adapter","Exhaust":{"fan1_input":0},"TG1D":{"temp1_input":-127}}}`, nil
+ },
+ sensorsParseFn: sensors.Parse,
+ sensorsPowerFn: func(context.Context) (*sensors.PowerData, error) {
+ return &sensors.PowerData{PackageWatts: 18, Available: true, Source: "rapl"}, nil
+ },
+ }
+ got := (&Agent{logger: zerolog.Nop(), collector: mc}).collectTemperatures(context.Background())
+ want := []agentshost.NativeSensor{
+ reportNativeSensor("applesmc-isa-0300", "ISA adapter", "temp1", "TG1D", agentshost.NativeSensorKindTemperature, -127, agentshost.NativeSensorStatusInvalid),
+ reportNativeSensor("applesmc-isa-0300", "ISA adapter", "fan1", "Exhaust", agentshost.NativeSensorKindFan, 0, agentshost.NativeSensorStatusOK),
+ }
+ if !reflect.DeepEqual(got.Native, want) {
+ t.Fatalf("native inventory = %+v, want %+v", got.Native, want)
+ }
+ if len(got.TemperatureCelsius) != 0 || len(got.Additional) != 0 || len(got.FanRPM) != 0 {
+ t.Fatalf("legacy maps = %+v, want them empty", got)
+ }
+ if len(got.PowerWatts) != 0 {
+ t.Fatalf("power readings = %+v, want the existing gate to skip power collection", got.PowerWatts)
+ }
+}
diff --git a/internal/hostagent/cluster_sensors.go b/internal/hostagent/cluster_sensors.go
index ddc64d5f70..b1f05a91b1 100644
--- a/internal/hostagent/cluster_sensors.go
+++ b/internal/hostagent/cluster_sensors.go
@@ -223,6 +223,10 @@ func (a *Agent) collectPeerSensors(ctx context.Context, peer clusterPeer, sshKey
return agentshost.Sensors{}, nil
}
- // Convert to flat sensor format using the shared helper
- return convertTemperatureDataToSensors(tempData), nil
+ // Convert to flat sensor format using the shared helper. Peer readings
+ // only feed node temperature, so the native inventory, which belongs to
+ // each host's own agent report, is not repeated for every peer.
+ result := convertTemperatureDataToSensors(tempData)
+ result.Native = nil
+ return result, nil
}
diff --git a/internal/hostagent/cluster_sensors_test.go b/internal/hostagent/cluster_sensors_test.go
index d2a43cba3b..383d6b5959 100644
--- a/internal/hostagent/cluster_sensors_test.go
+++ b/internal/hostagent/cluster_sensors_test.go
@@ -576,3 +576,26 @@ func TestClusterNodeSensorsType(t *testing.T) {
t.Error("expected cpu_package temperature")
}
}
+
+func TestCollectPeerSensors_OmitsNativeInventory(t *testing.T) {
+ a := &Agent{
+ logger: zerolog.Nop(),
+ collector: &mockCollector{
+ commandCombinedOutputFn: func(ctx context.Context, name string, arg ...string) (string, error) {
+ return `{"coretemp-isa-0000":{"Package id 0":{"temp1_input":52}},"nct6798-isa-0290":{"SYSTIN":{"temp1_input":33},"CPU Fan":{"fan1_input":900}}}`, nil
+ },
+ sensorsParseFn: sensors.Parse,
+ },
+ }
+
+ result, err := a.collectPeerSensors(context.Background(), clusterPeer{Name: "peer1", IP: "10.0.0.2"}, "/root/.ssh/id_rsa")
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+ if result.TemperatureCelsius["cpu_package"] != 52 {
+ t.Fatalf("peer cpu_package = %v, want 52", result.TemperatureCelsius["cpu_package"])
+ }
+ if result.Native != nil {
+ t.Fatalf("peer report carried a native inventory of %d sensors; it belongs to each host's own agent", len(result.Native))
+ }
+}
diff --git a/internal/models/converters.go b/internal/models/converters.go
index 57aba52a47..eb8c3ee799 100644
--- a/internal/models/converters.go
+++ b/internal/models/converters.go
@@ -897,7 +897,7 @@ func (s DockerSwarmInfo) ToFrontend() DockerSwarmFrontend {
}
func hostSensorSummaryToFrontend(src HostSensorSummary) *HostSensorSummaryFrontend {
- if len(src.TemperatureCelsius) == 0 && len(src.FanRPM) == 0 && len(src.PowerWatts) == 0 && len(src.Additional) == 0 && len(src.Custom) == 0 && len(src.GPU) == 0 && src.ThermalState == nil && len(src.SMART) == 0 {
+ if len(src.TemperatureCelsius) == 0 && len(src.FanRPM) == 0 && len(src.PowerWatts) == 0 && len(src.Additional) == 0 && len(src.Custom) == 0 && len(src.Native) == 0 && len(src.GPU) == 0 && src.ThermalState == nil && len(src.SMART) == 0 {
return nil
}
@@ -934,6 +934,7 @@ func hostSensorSummaryToFrontend(src HostSensorSummary) *HostSensorSummaryFronte
}
}
}
+ dest.Native = cloneHostNativeSensors(src.Native)
if len(src.GPU) > 0 {
dest.GPU = make([]HostGPUSensorFrontend, len(src.GPU))
for i, gpu := range src.GPU {
diff --git a/internal/models/deepcopy.go b/internal/models/deepcopy.go
index 184633c596..3785328e93 100644
--- a/internal/models/deepcopy.go
+++ b/internal/models/deepcopy.go
@@ -259,6 +259,7 @@ func cloneHostSensorSummary(src HostSensorSummary) HostSensorSummary {
PowerWatts: cloneStringFloat64Map(src.PowerWatts),
Additional: cloneStringFloat64Map(src.Additional),
Custom: cloneHostCustomSensors(src.Custom),
+ Native: cloneHostNativeSensors(src.Native),
GPU: cloneHostGPUSensors(src.GPU),
ThermalState: cloneHostThermalState(src.ThermalState),
SMART: cloneHostDiskSMART(src.SMART),
@@ -278,6 +279,18 @@ func cloneHostCustomSensors(src []HostCustomSensorMetric) []HostCustomSensorMetr
return dest
}
+func cloneHostNativeSensors(src []HostNativeSensor) []HostNativeSensor {
+ if len(src) == 0 {
+ return nil
+ }
+ dest := make([]HostNativeSensor, len(src))
+ for i, sensor := range src {
+ dest[i] = sensor
+ dest[i].Value = cloneFloat64Ptr(sensor.Value)
+ }
+ return dest
+}
+
func cloneHostGPUSensors(src []HostGPUSensor) []HostGPUSensor {
if len(src) == 0 {
return nil
diff --git a/internal/models/models.go b/internal/models/models.go
index b9c9596f51..f42a266391 100644
--- a/internal/models/models.go
+++ b/internal/models/models.go
@@ -762,11 +762,29 @@ type HostSensorSummary struct {
PowerWatts map[string]float64 `json:"powerWatts,omitempty"`
Additional map[string]float64 `json:"additional,omitempty"`
Custom []HostCustomSensorMetric `json:"custom,omitempty"`
+ Native []HostNativeSensor `json:"native,omitempty"`
GPU []HostGPUSensor `json:"gpu,omitempty"`
ThermalState *HostThermalState `json:"thermalState,omitempty"`
SMART []HostDiskSMART `json:"smart,omitempty"` // S.M.A.R.T. disk data
}
+// HostNativeSensor is one lm-sensors temperature or fan input from the host
+// agent's inventory. ID is the host-scoped "<chip>/<channel>" source key, not
+// a physical-device identity; Label is the chip's original feature name and is
+// not unique. Status "invalid" marks an implausible reading, judged on ingest,
+// and Value is nil when the chip gave no number.
+type HostNativeSensor struct {
+ ID string `json:"id"`
+ Chip string `json:"chip"`
+ Adapter string `json:"adapter,omitempty"`
+ Channel string `json:"channel"`
+ Label string `json:"label"`
+ Kind string `json:"kind"`
+ Unit string `json:"unit"`
+ Value *float64 `json:"value,omitempty"`
+ Status string `json:"status"`
+}
+
type HostCustomSensorMetric struct {
ID string `json:"id"`
Name string `json:"name"`
@@ -817,6 +835,9 @@ func (s HostSensorSummary) NormalizeCollections() HostSensorSummary {
if s.Custom == nil {
s.Custom = []HostCustomSensorMetric{}
}
+ if s.Native == nil {
+ s.Native = []HostNativeSensor{}
+ }
if s.GPU == nil {
s.GPU = []HostGPUSensor{}
}
diff --git a/internal/models/models_frontend.go b/internal/models/models_frontend.go
index 3c796e380e..0bea826e97 100644
--- a/internal/models/models_frontend.go
+++ b/internal/models/models_frontend.go
@@ -770,6 +770,7 @@ type HostSensorSummaryFrontend struct {
PowerWatts map[string]float64 `json:"powerWatts"`
Additional map[string]float64 `json:"additional"`
Custom []HostCustomSensorMetricFrontend `json:"custom"`
+ Native []HostNativeSensor `json:"native"`
GPU []HostGPUSensorFrontend `json:"gpu"`
ThermalState *HostThermalState `json:"thermalState,omitempty"`
SMART []HostDiskSMARTFrontend `json:"smart"` // S.M.A.R.T. disk data
@@ -816,6 +817,9 @@ func (s HostSensorSummaryFrontend) NormalizeCollections() HostSensorSummaryFront
if s.Custom == nil {
s.Custom = []HostCustomSensorMetricFrontend{}
}
+ if s.Native == nil {
+ s.Native = []HostNativeSensor{}
+ }
if s.GPU == nil {
s.GPU = []HostGPUSensorFrontend{}
}
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index 52735ddb5d..c9d4b63a5f 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -4219,6 +4219,22 @@ func hostSensorsFromReadStateView(sensors *unifiedresources.HostSensorMeta) mode
}
}
}
+ if len(sensors.Native) > 0 {
+ out.Native = make([]models.HostNativeSensor, len(sensors.Native))
+ for i, sensor := range sensors.Native {
+ out.Native[i] = models.HostNativeSensor{
+ ID: sensor.ID,
+ Chip: sensor.Chip,
+ Adapter: sensor.Adapter,
+ Channel: sensor.Channel,
+ Label: sensor.Label,
+ Kind: sensor.Kind,
+ Unit: sensor.Unit,
+ Value: cloneFloat64Ptr(sensor.Value),
+ Status: sensor.Status,
+ }
+ }
+ }
if len(sensors.GPU) > 0 {
out.GPU = make([]models.HostGPUSensor, len(sensors.GPU))
for i, gpu := range sensors.GPU {
diff --git a/internal/monitoring/monitor_agents.go b/internal/monitoring/monitor_agents.go
index a5df94fa92..ff42a8a809 100644
--- a/internal/monitoring/monitor_agents.go
+++ b/internal/monitoring/monitor_agents.go
@@ -3589,6 +3589,7 @@ func (m *Monitor) ApplyHostReport(report agentshost.Report, tokenRecord *config.
PowerWatts: cloneStringFloatMap(report.Sensors.PowerWatts),
Additional: cloneStringFloatMap(report.Sensors.Additional),
Custom: convertAgentCustomSensorsToModels(report.Sensors.Custom),
+ Native: convertAgentNativeSensorsToModels(report.Sensors.Native),
GPU: convertAgentGPUToModels(report.Sensors.GPU),
ThermalState: convertAgentThermalStateToModels(report.Sensors.ThermalState),
SMART: convertAgentSMARTToModels(report.Sensors.SMART),
diff --git a/internal/monitoring/monitor_helpers.go b/internal/monitoring/monitor_helpers.go
index 52ce71116b..8e4b37008a 100644
--- a/internal/monitoring/monitor_helpers.go
+++ b/internal/monitoring/monitor_helpers.go
@@ -10,6 +10,7 @@ import (
"time"
"github.com/rcourtman/pulse-go-rewrite/internal/models"
+ "github.com/rcourtman/pulse-go-rewrite/internal/sensors"
agentsdocker "github.com/rcourtman/pulse-go-rewrite/pkg/agents/docker"
agentshost "github.com/rcourtman/pulse-go-rewrite/pkg/agents/host"
"github.com/rcourtman/pulse-go-rewrite/pkg/diskinventory"
@@ -748,6 +749,65 @@ func convertAgentCustomSensorsToModels(metrics []agentshost.CustomSensorMetric)
return result
}
+// maxReportedNativeSensors bounds the native sensor inventory accepted from
+// one host report, matching the agent's own limit.
+const maxReportedNativeSensors = sensors.MaxNativeSensors
+
+// convertAgentNativeSensorsToModels accepts the agent's temperature and fan
+// inventory. An entry is kept only when its ID is exactly "<chip>/<channel>"
+// for a canonical tempN or fanN channel of the reported kind, so a malformed
+// report cannot describe one input under two identities. The unit follows the
+// kind, and the server recomputes the ok/invalid status with the shared
+// plausibility policy instead of trusting the agent's. A repeated ID keeps its
+// first entry.
+func convertAgentNativeSensorsToModels(reported []agentshost.NativeSensor) []models.HostNativeSensor {
+ if len(reported) == 0 {
+ return nil
+ }
+ result := make([]models.HostNativeSensor, 0, min(len(reported), maxReportedNativeSensors))
+ seen := make(map[string]struct{}, cap(result))
+ for _, sensor := range reported {
+ if len(result) == maxReportedNativeSensors {
+ break
+ }
+ chip := strings.TrimSpace(sensor.Chip)
+ channel := strings.TrimSpace(sensor.Channel)
+ kind := strings.TrimSpace(sensor.Kind)
+ id := strings.TrimSpace(sensor.ID)
+ channelKind, canonical := sensors.NativeSensorChannelKind(channel)
+ if chip == "" || !canonical || channelKind != kind || id != chip+"/"+channel {
+ continue
+ }
+ if _, duplicate := seen[id]; duplicate {
+ continue
+ }
+ seen[id] = struct{}{}
+ unit := agentshost.NativeSensorUnitCelsius
+ if kind == agentshost.NativeSensorKindFan {
+ unit = agentshost.NativeSensorUnitRPM
+ }
+ value := cloneFloat64Ptr(sensor.Value)
+ if value != nil && (math.IsNaN(*value) || math.IsInf(*value, 0)) {
+ value = nil
+ }
+ result = append(result, models.HostNativeSensor{
+ ID: id,
+ Chip: chip,
+ Adapter: strings.TrimSpace(sensor.Adapter),
+ Channel: channel,
+ Label: strings.TrimSpace(sensor.Label),
+ Kind: kind,
+ Unit: unit,
+ Value: value,
+ Status: sensors.NativeSensorStatus(kind, value),
+ })
+ }
+ if len(result) == 0 {
+ return nil
+ }
+ return result
+}
+
func convertAgentThermalStateToModels(src *agentshost.ThermalState) *models.HostThermalState {
if src == nil {
return nil
diff --git a/internal/monitoring/monitor_host_agents_test.go b/internal/monitoring/monitor_host_agents_test.go
index bd56f1c556..156ce6b283 100644
--- a/internal/monitoring/monitor_host_agents_test.go
+++ b/internal/monitoring/monitor_host_agents_test.go
@@ -11,6 +11,7 @@ import (
"os"
"reflect"
"slices"
+ "strconv"
"strings"
"sync/atomic"
"testing"
@@ -3582,6 +3583,103 @@ func TestApplyHostReportPreservesPowerSensorSummary(t *testing.T) {
}
}
+func TestApplyHostReportPreservesNativeSensorInventory(t *testing.T) {
+ monitor := &Monitor{
+ state: models.NewState(),
+ alertManager: alerts.NewManager(),
+ hostTokenBindings: make(map[string]string),
+ config: &config.Config{},
+ rateTracker: NewRateTracker(),
+ }
+ t.Cleanup(func() { monitor.alertManager.Stop() })
+
+ battery, unattached, fan := 34.2, -127.0, 6152.0
+ reportedBattery := battery
+ report := agentshost.Report{
+ Agent: agentshost.AgentInfo{ID: "agent-native", Version: "1.0.0", IntervalSeconds: 30},
+ Host: agentshost.HostInfo{ID: "machine-native", Hostname: "macbook-pve", MachineID: "machine-native"},
+ Metrics: agentshost.Metrics{
+ Memory: agentshost.MemoryMetric{TotalBytes: 1024, UsedBytes: 512, FreeBytes: 512, Usage: 50},
+ },
+ Sensors: agentshost.Sensors{
+ Additional: map[string]float64{"applesmc_tb0t": battery},
+ Native: []agentshost.NativeSensor{
+ {ID: " applesmc-isa-0300/temp1 ", Chip: "applesmc-isa-0300", Adapter: "ISA adapter", Channel: "temp1", Label: " TB0T ",
+ Kind: agentshost.NativeSensorKindTemperature, Unit: "kelvin", Value: &reportedBattery, Status: agentshost.NativeSensorStatusOK},
+ // The server judges plausibility itself, whatever the agent claims.
+ {ID: "applesmc-isa-0300/temp4", Chip: "applesmc-isa-0300", Channel: "temp4", Label: "TG1D",
+ Kind: agentshost.NativeSensorKindTemperature, Value: &unattached, Status: agentshost.NativeSensorStatusOK},
+ {ID: "applesmc-isa-0300/fan1", Chip: "applesmc-isa-0300", Channel: "fan1", Label: "Left side",
+ Kind: agentshost.NativeSensorKindFan, Unit: agentshost.NativeSensorUnitRPM, Value: &fan, Status: agentshost.NativeSensorStatusOK},
+ {ID: "applesmc-isa-0300/temp2", Chip: "applesmc-isa-0300", Channel: "temp2", Label: "TB1T",
+ Kind: agentshost.NativeSensorKindTemperature, Status: agentshost.NativeSensorStatusOK},
+ {ID: "applesmc-isa-0300/temp1", Chip: "applesmc-isa-0300", Channel: "temp1", Label: "duplicate",
+ Kind: agentshost.NativeSensorKindTemperature, Status: agentshost.NativeSensorStatusOK},
+ // Identities that do not follow "<chip>/<channel>" for a canonical
+ // channel of the reported kind are rejected.
+ {ID: "applesmc-isa-0300/temp9", Chip: "applesmc-isa-0300", Channel: "temp8", Label: "mismatch",
+ Kind: agentshost.NativeSensorKindTemperature, Value: &battery, Status: agentshost.NativeSensorStatusOK},
+ {ID: "applesmc-isa-0300/temp01", Chip: "applesmc-isa-0300", Channel: "temp01", Label: "leading zero",
+ Kind: agentshost.NativeSensorKindTemperature, Value: &battery, Status: agentshost.NativeSensorStatusOK},
+ {ID: "applesmc-isa-0300/fan2", Chip: "applesmc-isa-0300", Channel: "fan2", Label: "wrong kind",
+ Kind: agentshost.NativeSensorKindTemperature, Value: &battery, Status: agentshost.NativeSensorStatusOK},
+ {ID: "/temp3", Channel: "temp3", Label: "no chip", Kind: agentshost.NativeSensorKindTemperature, Value: &battery, Status: agentshost.NativeSensorStatusOK},
+ {ID: "", Label: "no identity", Kind: agentshost.NativeSensorKindTemperature, Status: agentshost.NativeSensorStatusOK},
+ {ID: "board-isa-0000/in0", Label: "Vcore", Kind: "voltage", Status: agentshost.NativeSensorStatusOK},
+ },
+ },
+ Timestamp: time.Now().UTC(),
+ }
+
+ host, err := monitor.ApplyHostReport(report, nil)
+ if err != nil {
+ t.Fatalf("ApplyHostReport: %v", err)
+ }
+ want := []models.HostNativeSensor{
+ {ID: "applesmc-isa-0300/temp1", Chip: "applesmc-isa-0300", Adapter: "ISA adapter", Channel: "temp1", Label: "TB0T",
+ Kind: agentshost.NativeSensorKindTemperature, Unit: agentshost.NativeSensorUnitCelsius, Value: &battery, Status: agentshost.NativeSensorStatusOK},
+ {ID: "applesmc-isa-0300/temp4", Chip: "applesmc-isa-0300", Channel: "temp4", Label: "TG1D",
+ Kind: agentshost.NativeSensorKindTemperature, Unit: agentshost.NativeSensorUnitCelsius, Value: &unattached, Status: agentshost.NativeSensorStatusInvalid},
+ {ID: "applesmc-isa-0300/fan1", Chip: "applesmc-isa-0300", Channel: "fan1", Label: "Left side",
+ Kind: agentshost.NativeSensorKindFan, Unit: agentshost.NativeSensorUnitRPM, Value: &fan, Status: agentshost.NativeSensorStatusOK},
+ {ID: "applesmc-isa-0300/temp2", Chip: "applesmc-isa-0300", Channel: "temp2", Label: "TB1T",
+ Kind: agentshost.NativeSensorKindTemperature, Unit: agentshost.NativeSensorUnitCelsius, Status: agentshost.NativeSensorStatusInvalid},
+ }
+ if !reflect.DeepEqual(host.Sensors.Native, want) {
+ t.Fatalf("native inventory = %+v, want %+v", host.Sensors.Native, want)
+ }
+ if host.Sensors.Additional["applesmc_tb0t"] != battery {
+ t.Fatalf("legacy additional reading = %+v, want it unchanged", host.Sensors.Additional)
+ }
+ *report.Sensors.Native[0].Value = 99
+ if got := *host.Sensors.Native[0].Value; got != battery {
+ t.Fatalf("host inventory shares the report's value pointer, got %.1f want %.1f", got, battery)
+ }
+
+ frontend := host.ToFrontend()
+ if frontend.Sensors == nil || len(frontend.Sensors.Native) != len(want) || frontend.Sensors.Native[0].Label != "TB0T" {
+ t.Fatalf("frontend inventory = %+v, want the four accepted sensors", frontend.Sensors)
+ }
+
+ oversized := make([]agentshost.NativeSensor, 300)
+ for i := range oversized {
+ channel := "temp" + strconv.Itoa(i+1)
+ oversized[i] = agentshost.NativeSensor{ID: "board-isa-0000/" + channel, Chip: "board-isa-0000", Channel: channel,
+ Kind: agentshost.NativeSensorKindTemperature, Value: &battery}
+ }
+ if got := convertAgentNativeSensorsToModels(oversized); len(got) != 256 || got[255].ID != "board-isa-0000/temp256" {
+ t.Fatalf("server kept %d native sensors, want the first 256", len(got))
+ }
+
+ projected := hostSensorsFromReadStateView(&unifiedresources.HostSensorMeta{
+ Native: []unifiedresources.HostNativeSensor{{ID: "applesmc-isa-0300/temp1", Chip: "applesmc-isa-0300", Channel: "temp1", Label: "TB0T",
+ Kind: agentshost.NativeSensorKindTemperature, Unit: agentshost.NativeSensorUnitCelsius, Value: &battery, Status: agentshost.NativeSensorStatusOK}},
+ })
+ if len(projected.Native) != 1 || projected.Native[0].Value == nil || *projected.Native[0].Value != battery || projected.Native[0].Label != "TB0T" {
+ t.Fatalf("read-state inventory projection = %+v, want the battery sensor", projected.Native)
+ }
+}
+
func TestApplyHostReportPersistsSMARTMetricsForAgentDisksWithFallbackID(t *testing.T) {
t.Helper()
diff --git a/internal/sensors/native.go b/internal/sensors/native.go
new file mode 100644
index 0000000000..01ba4d64cf
--- /dev/null
+++ b/internal/sensors/native.go
@@ -0,0 +1,219 @@
+package sensors
+
+import (
+ "math"
+ "sort"
+ "strconv"
+ "strings"
+
+ agentshost "github.com/rcourtman/pulse-go-rewrite/pkg/agents/host"
+ "github.com/rs/zerolog/log"
+)
+
+// The inventory vocabulary is the agent report's, so the parser and the wire
+// format cannot drift.
+const (
+ NativeSensorKindTemperature = agentshost.NativeSensorKindTemperature
+ NativeSensorKindFan = agentshost.NativeSensorKindFan
+
+ NativeSensorUnitCelsius = agentshost.NativeSensorUnitCelsius
+ NativeSensorUnitRPM = agentshost.NativeSensorUnitRPM
+
+ NativeSensorStatusOK = agentshost.NativeSensorStatusOK
+ NativeSensorStatusInvalid = agentshost.NativeSensorStatusInvalid
+
+ // MaxNativeSensors bounds the inventory one host reports. Laptops and
+ // boards with an SMC or Super I/O chip expose about 50 inputs; anything
+ // beyond this is truncated in stable ID order rather than growing the
+ // report without limit.
+ MaxNativeSensors = 256
+
+ // Common sensor ICs are rated from -55 °C, and the parser already treats
+ // readings above 150 °C as implausible. Chips report values outside that
+ // band, such as applesmc's -127 °C, for inputs with nothing attached.
+ minPlausibleNativeCelsius = -55.0
+ maxPlausibleNativeCelsius = 150.0
+)
+
+// NativeSensor is one lm-sensors temperature or fan input as the host
+// reported it. ID joins the full chip name, including its bus address, to the
+// native input channel. It is a host-scoped source key: two chips of one type
+// and labels that differ only by case get separate IDs, and an ID stays the
+// same while the kernel enumerates the chip the same way. It is not a
+// physical-device identity, so a moved PCI address or renumbered channel can
+// change or reuse it. Label keeps the chip's original feature name. Values are
+// the Celsius or RPM lm-sensors reports, unconverted; a finite value outside
+// the plausible range is kept with an invalid status, and a non-finite value is
+// omitted.
+type NativeSensor struct {
+ ID string
+ Chip string
+ Adapter string
+ Channel string
+ Label string
+ Kind string
+ Unit string
+ Value *float64
+ Status string
+}
+
+// collectNativeSensors lists every temperature and fan input of one chip.
+func collectNativeSensors(chipName string, chipMap map[string]interface{}) []NativeSensor {
+ adapter, _ := chipMap["Adapter"].(string)
+ var result []NativeSensor
+ for label, featureData := range chipMap {
+ featureMap, ok := featureData.(map[string]interface{})
+ if !ok {
+ continue
+ }
+ for key, raw := range featureMap {
+ channel, found := strings.CutSuffix(key, "_input")
+ if !found {
+ continue
+ }
+ kind, ok := NativeSensorChannelKind(channel)
+ if !ok {
+ continue
+ }
+ sensor := NativeSensor{
+ ID: chipName + "/" + channel,
+ Chip: chipName,
+ Adapter: adapter,
+ Channel: channel,
+ Label: label,
+ Kind: kind,
+ }
+ if value, finite := nativeSensorValue(raw); finite {
+ sensor.Value = &value
+ }
+ sensor.Status = NativeSensorStatus(kind, sensor.Value)
+ if kind == NativeSensorKindTemperature {
+ sensor.Unit = NativeSensorUnitCelsius
+ } else {
+ sensor.Unit = NativeSensorUnitRPM
+ }
+ result = append(result, sensor)
+ }
+ }
+ return result
+}
+
+// NativeSensorChannelKind returns the kind of a canonical lm-sensors channel
+// name: tempN or fanN, where N is decimal without leading zeros. Any other
+// spelling is rejected so one input cannot appear under two channel names.
+func NativeSensorChannelKind(channel string) (string, bool) {
+ var kind, index string
+ switch {
+ case strings.HasPrefix(channel, "temp"):
+ kind, index = NativeSensorKindTemperature, strings.TrimPrefix(channel, "temp")
+ case strings.HasPrefix(channel, "fan"):
+ kind, index = NativeSensorKindFan, strings.TrimPrefix(channel, "fan")
+ default:
+ return "", false
+ }
+ if index == "" || (len(index) > 1 && index[0] == '0') {
+ return "", false
+ }
+ for _, digit := range index {
+ if digit < '0' || digit > '9' {
+ return "", false
+ }
+ }
+ return kind, true
+}
+
+// NativeSensorStatus is the plausibility policy for a native reading: ok
+// needs a finite value, from -55 to 150 °C for a temperature or at least
+// 0 RPM for a fan. The agent and the server's report ingest both apply it, so
+// the server's judgement does not depend on the agent's version.
+func NativeSensorStatus(kind string, value *float64) string {
+ if value == nil || math.IsNaN(*value) || math.IsInf(*value, 0) {
+ return NativeSensorStatusInvalid
+ }
+ switch kind {
+ case NativeSensorKindTemperature:
+ if *value >= minPlausibleNativeCelsius && *value <= maxPlausibleNativeCelsius {
+ return NativeSensorStatusOK
+ }
+ case NativeSensorKindFan:
+ // A stopped fan reads 0 RPM, which is a real observation.
+ if *value >= 0 {
+ return NativeSensorStatusOK
+ }
+ }
+ return NativeSensorStatusInvalid
+}
+
+func nativeSensorValue(raw interface{}) (float64, bool) {
+ var value float64
+ switch v := raw.(type) {
+ case float64:
+ value = v
+ case int:
+ value = float64(v)
+ case int64:
+ value = float64(v)
+ case string:
+ parsed, err := strconv.ParseFloat(strings.TrimSpace(v), 64)
+ if err != nil {
+ return 0, false
+ }
+ value = parsed
+ default:
+ return 0, false
+ }
+ if math.IsNaN(value) || math.IsInf(value, 0) {
+ return 0, false
+ }
+ return value, true
+}
+
+func nativeSensorChannelIndex(sensor NativeSensor) int {
+ prefix := "temp"
+ if sensor.Kind == NativeSensorKindFan {
+ prefix = "fan"
+ }
+ index, _ := strconv.Atoi(strings.TrimPrefix(sensor.Channel, prefix))
+ return index
+}
+
+// sortAndBoundNativeSensors orders the inventory by chip, then kind, then
+// channel number, keeps one entry per ID and drops entries beyond
+// MaxNativeSensors. lm-sensors names each subfeature once per chip; a
+// malformed report that repeats one keeps the first label in sort order.
+// Truncation drops the last chips in name order, so a newly added chip can
+// displace another chip's inputs; consumers must not read a missing entry as
+// a removed sensor.
+func sortAndBoundNativeSensors(inventory []NativeSensor) []NativeSensor {
+ sort.Slice(inventory, func(i, j int) bool {
+ a, b := inventory[i], inventory[j]
+ if a.Chip != b.Chip {
+ return a.Chip < b.Chip
+ }
+ if a.Kind != b.Kind {
+ return a.Kind == NativeSensorKindTemperature
+ }
+ if ai, bi := nativeSensorChannelIndex(a), nativeSensorChannelIndex(b); ai != bi {
+ return ai < bi
+ }
+ return a.Label < b.Label
+ })
+ unique := inventory[:0]
+ seen := make(map[string]struct{}, len(inventory))
+ for _, sensor := range inventory {
+ if _, duplicate := seen[sensor.ID]; duplicate {
+ continue
+ }
+ seen[sensor.ID] = struct{}{}
+ unique = append(unique, sensor)
+ }
+ inventory = unique
+ if len(inventory) > MaxNativeSensors {
+ log.Debug().
+ Int("reported", len(inventory)).
+ Int("kept", MaxNativeSensors).
+ Msg("Truncated native sensor inventory")
+ inventory = inventory[:MaxNativeSensors]
+ }
+ return inventory
+}
diff --git a/internal/sensors/parser.go b/internal/sensors/parser.go
index 7f0eca4da5..b083eb5314 100644
--- a/internal/sensors/parser.go
+++ b/internal/sensors/parser.go
@@ -20,6 +20,7 @@ type TemperatureData struct {
GPU map[string]float64 // GPU temperatures (e.g., "amdgpu-pci-0400": 55.0)
Fans map[string]float64 // Fan speeds in RPM (e.g., "cpu_fan": 1200)
Other map[string]float64 // Other temperatures (DDR5, mobo, etc.)
+ Native []NativeSensor // Every temperature and fan input, by stable chip/channel ID
Available bool // Whether any temperature data was found
}
@@ -74,7 +75,10 @@ func Parse(jsonStr string) (*TemperatureData, error) {
// Parse all fans and other temperatures from every chip
parseFansAndOther(chipName, chipMap, data)
+
+ data.Native = append(data.Native, collectNativeSensors(chipName, chipMap)...)
}
+ data.Native = sortAndBoundNativeSensors(data.Native)
// If we got CPU temps, calculate max from cores if package not available
if data.CPUPackage == 0 && len(data.Cores) > 0 {
diff --git a/internal/sensors/parser_units_test.go b/internal/sensors/parser_units_test.go
index 3bb9a9f21a..67f1382eac 100644
--- a/internal/sensors/parser_units_test.go
+++ b/internal/sensors/parser_units_test.go
@@ -4,6 +4,7 @@ import (
"encoding/json"
"math"
"os"
+ "strconv"
"testing"
"github.com/stretchr/testify/require"
@@ -36,9 +37,119 @@ func TestParseMixedSensorUnits(t *testing.T) {
GPU: map[string]float64{"amdgpu-pci-0300_edge": 58},
Fans: map[string]float64{"applesmc_left_side": 6152, "applesmc_right_side": 5699},
Other: map[string]float64{"applesmc_tb0t": 34.2, "applesmc_tb1t": 29.2, "applesmc_th1h": 44.5},
+ Native: []NativeSensor{
+ nativeTemp("amdgpu-pci-0300", "", "temp1", "edge", 58, NativeSensorStatusOK),
+ nativeTemp("applesmc-isa-0300", "ISA adapter", "temp1", "TB0T", 34.2, NativeSensorStatusOK),
+ nativeTemp("applesmc-isa-0300", "ISA adapter", "temp2", "TB1T", 29.2, NativeSensorStatusOK),
+ nativeTemp("applesmc-isa-0300", "ISA adapter", "temp3", "Th1H", 44.5, NativeSensorStatusOK),
+ nativeTemp("applesmc-isa-0300", "ISA adapter", "temp4", "TG1D", -127, NativeSensorStatusInvalid),
+ nativeTemp("applesmc-isa-0300", "ISA adapter", "temp5", "TCMc", 0, NativeSensorStatusOK),
+ nativeFan("applesmc-isa-0300", "ISA adapter", "fan1", "Left side", 6152, NativeSensorStatusOK),
+ nativeFan("applesmc-isa-0300", "ISA adapter", "fan2", "Right side", 5699, NativeSensorStatusOK),
+ nativeTemp("coretemp-isa-0000", "", "temp1", "Package id 0", 91, NativeSensorStatusOK),
+ nativeTemp("coretemp-isa-0000", "", "temp2", "Core 0", 87, NativeSensorStatusOK),
+ nativeTemp("nvme-pci-0200", "", "temp1", "Composite", 36.9, NativeSensorStatusOK),
+ },
}, got, "compare the complete report, not only selected expected readings")
}
+func nativeTemp(chip, adapter, channel, label string, value float64, status string) NativeSensor {
+ return NativeSensor{ID: chip + "/" + channel, Chip: chip, Adapter: adapter, Channel: channel, Label: label,
+ Kind: NativeSensorKindTemperature, Unit: NativeSensorUnitCelsius, Value: &value, Status: status}
+}
+
+func nativeFan(chip, adapter, channel, label string, value float64, status string) NativeSensor {
+ return NativeSensor{ID: chip + "/" + channel, Chip: chip, Adapter: adapter, Channel: channel, Label: label,
+ Kind: NativeSensorKindFan, Unit: NativeSensorUnitRPM, Value: &value, Status: status}
+}
+
+func TestParseNativeInventoryKeepsDistinctIdentities(t *testing.T) {
+ // Two chips of one type and labels that differ only by case collide in
+ // the legacy flat maps; the native inventory keeps every input apart.
+ input := `{
+ "nvme-pci-0100": {"Composite": {"temp1_input": 41}},
+ "nvme-pci-0200": {"Composite": {"temp1_input": 47}},
+ "applesmc-isa-0300": {"TC1F": {"temp1_input": 96.8}, "TC1f": {"temp2_input": 95.1}}
+ }`
+ for range 16 {
+ got, err := Parse(input)
+ require.NoError(t, err)
+ require.Equal(t, []NativeSensor{
+ nativeTemp("applesmc-isa-0300", "", "temp1", "TC1F", 96.8, NativeSensorStatusOK),
+ nativeTemp("applesmc-isa-0300", "", "temp2", "TC1f", 95.1, NativeSensorStatusOK),
+ nativeTemp("nvme-pci-0100", "", "temp1", "Composite", 41, NativeSensorStatusOK),
+ nativeTemp("nvme-pci-0200", "", "temp1", "Composite", 47, NativeSensorStatusOK),
+ }, got.Native, "inventory order and identity must not depend on map iteration")
+ require.Len(t, got.Other, 1, "the legacy map still collapses the case-only pair")
+ }
+}
+
+func TestParseNativeInventoryStatusAndUnits(t *testing.T) {
+ got, err := Parse(`{"board-isa-0a20": {
+ "Adapter": "ISA adapter",
+ "SYSTIN": {"temp1_input": 31000, "temp1_max": 80},
+ "AUXTIN": {"temp2_input": 150.5},
+ "Cold": {"temp3_input": -55.5},
+ "Probe": {"temp4_input": "nan"},
+ "Floor": {"temp5_input": -55},
+ "Ceiling": {"temp6_input": "150"},
+ "Stopped": {"fan1_input": 0},
+ "Broken": {"fan2_input": -1},
+ "Vcore": {"in0_input": 1.1},
+ "Odd": {"tempx_input": 40, "temp_input": 40, "temp07_input": 40, "fan1_min": 300}
+ }}`)
+ require.NoError(t, err)
+ require.Equal(t, []NativeSensor{
+ nativeTemp("board-isa-0a20", "ISA adapter", "temp1", "SYSTIN", 31000, NativeSensorStatusInvalid),
+ nativeTemp("board-isa-0a20", "ISA adapter", "temp2", "AUXTIN", 150.5, NativeSensorStatusInvalid),
+ nativeTemp("board-isa-0a20", "ISA adapter", "temp3", "Cold", -55.5, NativeSensorStatusInvalid),
+ {ID: "board-isa-0a20/temp4", Chip: "board-isa-0a20", Adapter: "ISA adapter", Channel: "temp4", Label: "Probe",
+ Kind: NativeSensorKindTemperature, Unit: NativeSensorUnitCelsius, Status: NativeSensorStatusInvalid},
+ nativeTemp("board-isa-0a20", "ISA adapter", "temp5", "Floor", -55, NativeSensorStatusOK),
+ nativeTemp("board-isa-0a20", "ISA adapter", "temp6", "Ceiling", 150, NativeSensorStatusOK),
+ nativeFan("board-isa-0a20", "ISA adapter", "fan1", "Stopped", 0, NativeSensorStatusOK),
+ nativeFan("board-isa-0a20", "ISA adapter", "fan2", "Broken", -1, NativeSensorStatusInvalid),
+ }, got.Native, "values stay as reported (no millidegree guess), the band is inclusive, implausible values stay visible as invalid, a stopped fan is a reading, non-canonical channels are ignored")
+ for _, sensor := range got.Native {
+ if sensor.Value != nil {
+ require.False(t, math.IsNaN(*sensor.Value) || math.IsInf(*sensor.Value, 0), "inventory values must be JSON encodable")
+ }
+ }
+}
+
+func TestNativeSensorChannelKindAndStatus(t *testing.T) {
+ for channel, want := range map[string]string{"temp1": NativeSensorKindTemperature, "temp12": NativeSensorKindTemperature, "fan3": NativeSensorKindFan, "temp0": NativeSensorKindTemperature} {
+ kind, ok := NativeSensorChannelKind(channel)
+ require.True(t, ok, channel)
+ require.Equal(t, want, kind, channel)
+ }
+ for _, channel := range []string{"", "temp", "fan", "temp01", "fan007", "tempx", "in0", "Temp1", "temp1_input", "temp-1"} {
+ _, ok := NativeSensorChannelKind(channel)
+ require.False(t, ok, "%q must not be a canonical channel", channel)
+ }
+ value := func(v float64) *float64 { return &v }
+ require.Equal(t, NativeSensorStatusInvalid, NativeSensorStatus(NativeSensorKindTemperature, nil))
+ require.Equal(t, NativeSensorStatusInvalid, NativeSensorStatus(NativeSensorKindTemperature, value(math.NaN())))
+ require.Equal(t, NativeSensorStatusInvalid, NativeSensorStatus(NativeSensorKindFan, value(math.Inf(1))))
+ require.Equal(t, NativeSensorStatusInvalid, NativeSensorStatus("voltage", value(1)))
+ require.Equal(t, NativeSensorStatusOK, NativeSensorStatus(NativeSensorKindFan, value(0)))
+}
+
+func TestSortAndBoundNativeSensors(t *testing.T) {
+ inventory := make([]NativeSensor, 0, MaxNativeSensors+11)
+ for i := MaxNativeSensors + 9; i >= 0; i-- {
+ inventory = append(inventory, nativeTemp("chip-isa-0000", "", "temp"+strconv.Itoa(i+1), "T", 40, NativeSensorStatusOK))
+ }
+ inventory = append(inventory, nativeTemp("chip-isa-0000", "", "temp1", "Duplicate", 40, NativeSensorStatusOK))
+ got := sortAndBoundNativeSensors(inventory)
+ require.Len(t, got, MaxNativeSensors)
+ require.Equal(t, "chip-isa-0000/temp1", got[0].ID)
+ require.Equal(t, "Duplicate", got[0].Label, "a repeated ID keeps the first label in sort order")
+ require.Equal(t, "chip-isa-0000/temp2", got[1].ID, "the repeated ID is dropped")
+ require.Equal(t, "chip-isa-0000/temp"+strconv.Itoa(MaxNativeSensors), got[MaxNativeSensors-1].ID, "truncation keeps the lowest channels")
+ require.Nil(t, sortAndBoundNativeSensors(nil))
+}
+
func TestParseNonTemperatureInputsCannotImpersonateTypedReadings(t *testing.T) {
for _, chip := range []struct{ name, label string }{
{"coretemp-isa-0000", "Package id 0"},
diff --git a/internal/unifiedresources/adapters.go b/internal/unifiedresources/adapters.go
index e5faa2dbfb..e6a6d12b60 100644
--- a/internal/unifiedresources/adapters.go
+++ b/internal/unifiedresources/adapters.go
@@ -261,7 +261,7 @@ func resourceFromHost(host models.Host) (Resource, ResourceIdentity) {
storageAssessments := make([]storagehealth.Assessment, 0, len(host.RAID)+1)
// Populate sensors
- if len(host.Sensors.TemperatureCelsius) > 0 || len(host.Sensors.FanRPM) > 0 || len(host.Sensors.PowerWatts) > 0 || len(host.Sensors.Additional) > 0 || len(host.Sensors.Custom) > 0 || len(host.Sensors.GPU) > 0 || host.Sensors.ThermalState != nil || len(host.Sensors.SMART) > 0 {
+ if len(host.Sensors.TemperatureCelsius) > 0 || len(host.Sensors.FanRPM) > 0 || len(host.Sensors.PowerWatts) > 0 || len(host.Sensors.Additional) > 0 || len(host.Sensors.Custom) > 0 || len(host.Sensors.Native) > 0 || len(host.Sensors.GPU) > 0 || host.Sensors.ThermalState != nil || len(host.Sensors.SMART) > 0 {
sensorMeta := &HostSensorMeta{}
if len(host.Sensors.TemperatureCelsius) > 0 {
sensorMeta.TemperatureCelsius = make(map[string]float64, len(host.Sensors.TemperatureCelsius))
@@ -307,6 +307,22 @@ func resourceFromHost(host models.Host) (Resource, ResourceIdentity) {
}
}
}
+ if len(host.Sensors.Native) > 0 {
+ sensorMeta.Native = make([]HostNativeSensor, len(host.Sensors.Native))
+ for i, sensor := range host.Sensors.Native {
+ sensorMeta.Native[i] = HostNativeSensor{
+ ID: sensor.ID,
+ Chip: sensor.Chip,
+ Adapter: sensor.Adapter,
+ Channel: sensor.Channel,
+ Label: sensor.Label,
+ Kind: sensor.Kind,
+ Unit: sensor.Unit,
+ Value: cloneFloat64Ptr(sensor.Value),
+ Status: sensor.Status,
+ }
+ }
+ }
if len(host.Sensors.GPU) > 0 {
sensorMeta.GPU = make([]HostGPUSensor, len(host.Sensors.GPU))
for i, gpu := range host.Sensors.GPU {
diff --git a/internal/unifiedresources/adapters_test.go b/internal/unifiedresources/adapters_test.go
index 0980cffaeb..ce47394269 100644
--- a/internal/unifiedresources/adapters_test.go
+++ b/internal/unifiedresources/adapters_test.go
@@ -105,6 +105,42 @@ func TestResourceFromHostProjectsXCPNGPoolIdentity(t *testing.T) {
}
}
+func TestResourceFromHostPreservesNativeSensorInventory(t *testing.T) {
+ battery, unattached := 34.2, -127.0
+ host := models.Host{
+ ID: "host-macbook",
+ Hostname: "macbook-pve",
+ Status: "online",
+ LastSeen: time.Date(2026, 10, 31, 12, 0, 0, 0, time.UTC),
+ Sensors: models.HostSensorSummary{
+ Native: []models.HostNativeSensor{
+ {ID: "applesmc-isa-0300/temp1", Chip: "applesmc-isa-0300", Adapter: "ISA adapter", Channel: "temp1", Label: "TB0T",
+ Kind: "temperature", Unit: "celsius", Value: &battery, Status: "ok"},
+ {ID: "applesmc-isa-0300/temp4", Chip: "applesmc-isa-0300", Adapter: "ISA adapter", Channel: "temp4", Label: "TG1D",
+ Kind: "temperature", Unit: "celsius", Value: &unattached, Status: "invalid"},
+ },
+ },
+ }
+
+ rr := NewRegistry(nil)
+ rr.IngestSnapshot(models.StateSnapshot{Hosts: []models.Host{host}})
+ agents := rr.ListByType(ResourceTypeAgent)
+ if len(agents) != 1 || agents[0].Agent == nil || agents[0].Agent.Sensors == nil {
+ t.Fatalf("expected one agent resource with sensors, got %+v", agents)
+ }
+ native := agents[0].Agent.Sensors.Native
+ if len(native) != 2 || native[0].ID != "applesmc-isa-0300/temp1" || native[0].Label != "TB0T" || native[0].Value == nil || *native[0].Value != battery ||
+ native[1].Status != "invalid" || native[1].Value == nil || *native[1].Value != unattached {
+ t.Fatalf("registry native inventory = %+v, want TB0T then the invalid TG1D", native)
+ }
+
+ *host.Sensors.Native[0].Value = 99
+ again := rr.ListByType(ResourceTypeAgent)[0].Agent.Sensors.Native[0]
+ if again.Value == nil || *again.Value != 34.2 {
+ t.Fatalf("registry inventory value = %v, want 34.2 independent of the source host", again.Value)
+ }
+}
+
func TestResourceFromHostPreservesCustomSensorMeta(t *testing.T) {
value := 12.5
observedAt := time.Date(2026, 7, 30, 19, 0, 0, 0, time.UTC)
diff --git a/internal/unifiedresources/clone.go b/internal/unifiedresources/clone.go
index 07988e342f..5a4941a1d9 100644
--- a/internal/unifiedresources/clone.go
+++ b/internal/unifiedresources/clone.go
@@ -869,6 +869,7 @@ func cloneHostSensorMeta(in *HostSensorMeta) *HostSensorMeta {
out.PowerWatts = cloneStringFloat64Map(in.PowerWatts)
out.Additional = cloneStringFloat64Map(in.Additional)
out.Custom = cloneHostCustomSensors(in.Custom)
+ out.Native = cloneHostNativeSensors(in.Native)
out.GPU = cloneHostGPUSensors(in.GPU)
out.ThermalState = cloneHostThermalState(in.ThermalState)
out.SMART = cloneHostSMARTMetaSlice(in.SMART)
@@ -888,6 +889,18 @@ func cloneHostCustomSensors(in []HostCustomSensorMetric) []HostCustomSensorMetri
return out
}
+func cloneHostNativeSensors(in []HostNativeSensor) []HostNativeSensor {
+ if len(in) == 0 {
+ return nil
+ }
+ out := make([]HostNativeSensor, len(in))
+ for i, sensor := range in {
+ out[i] = sensor
+ out[i].Value = cloneFloat64Ptr(sensor.Value)
+ }
+ return out
+}
+
func cloneHostGPUSensors(in []HostGPUSensor) []HostGPUSensor {
if len(in) == 0 {
return nil
diff --git a/internal/unifiedresources/clone_test.go b/internal/unifiedresources/clone_test.go
index dbf977dee3..42f75da95f 100644
--- a/internal/unifiedresources/clone_test.go
+++ b/internal/unifiedresources/clone_test.go
@@ -77,6 +77,24 @@ func TestCloneResourceRefreshesScopeAndPolicyMetadata(t *testing.T) {
// --- cloneResource: top-level isolation ---
+func TestCloneHostSensorMetaIsolatesNativeInventory(t *testing.T) {
+ battery := 34.2
+ original := &HostSensorMeta{Native: []HostNativeSensor{{ID: "applesmc-isa-0300/temp1", Chip: "applesmc-isa-0300", Channel: "temp1",
+ Label: "TB0T", Kind: "temperature", Unit: "celsius", Value: &battery, Status: "ok"}}}
+ clone := cloneHostSensorMeta(original)
+ if !reflect.DeepEqual(clone.Native, original.Native) {
+ t.Fatalf("cloned inventory = %+v, want %+v", clone.Native, original.Native)
+ }
+ *clone.Native[0].Value = 12
+ clone.Native[0].Label = "changed"
+ if *original.Native[0].Value != 34.2 || original.Native[0].Label != "TB0T" {
+ t.Fatalf("clone shares inventory memory with the original: %+v", original.Native[0])
+ }
+ if cloneHostSensorMeta(&HostSensorMeta{}).Native != nil {
+ t.Fatal("an empty inventory must stay nil through clone")
+ }
+}
+
func TestCloneResource_Nil(t *testing.T) {
out := cloneResource(nil)
if out.ID != "" {
diff --git a/internal/unifiedresources/types.go b/internal/unifiedresources/types.go
index 7c16a1f51d..0567966f58 100644
--- a/internal/unifiedresources/types.go
+++ b/internal/unifiedresources/types.go
@@ -648,11 +648,28 @@ type HostSensorMeta struct {
PowerWatts map[string]float64 `json:"powerWatts,omitempty"`
Additional map[string]float64 `json:"additional,omitempty"`
Custom []HostCustomSensorMetric `json:"custom,omitempty"`
+ Native []HostNativeSensor `json:"native,omitempty"`
GPU []HostGPUSensor `json:"gpu,omitempty"`
ThermalState *HostThermalState `json:"thermalState,omitempty"`
SMART []HostSMARTMeta `json:"smart,omitempty"`
}
+// HostNativeSensor is one lm-sensors temperature or fan input from a host
+// agent's inventory, keyed by its host-scoped "<chip>/<channel>" source key.
+// The key stays the same while the kernel enumerates the chip the same way;
+// it is not a physical-device identity.
+type HostNativeSensor struct {
+ ID string `json:"id"`
+ Chip string `json:"chip"`
+ Adapter string `json:"adapter,omitempty"`
+ Channel string `json:"channel"`
+ Label string `json:"label"`
+ Kind string `json:"kind"`
+ Unit string `json:"unit"`
+ Value *float64 `json:"value,omitempty"`
+ Status string `json:"status"`
+}
+
type HostCustomSensorMetric struct {
ID string `json:"id"`
Name string `json:"name"`
diff --git a/pkg/agents/host/report.go b/pkg/agents/host/report.go
index 1dacea3bc7..e9bab8028d 100644
--- a/pkg/agents/host/report.go
+++ b/pkg/agents/host/report.go
@@ -369,6 +369,7 @@ type Sensors struct {
PowerWatts map[string]float64 `json:"powerWatts,omitempty"` // Power consumption (e.g., cpu_package, dram)
Additional map[string]float64 `json:"additional,omitempty"`
Custom []CustomSensorMetric `json:"custom,omitempty"`
+ Native []NativeSensor `json:"native,omitempty"`
GPU []GPUSensor `json:"gpu,omitempty"`
ThermalState *ThermalState `json:"thermalState,omitempty"`
SMART []DiskSMART `json:"smart,omitempty"` // S.M.A.R.T. disk data
@@ -403,6 +404,40 @@ type CustomSensorMetric struct {
Stale bool `json:"stale,omitempty"`
}
+const (
+ NativeSensorKindTemperature = "temperature"
+ NativeSensorKindFan = "fan"
+ NativeSensorUnitCelsius = "celsius"
+ NativeSensorUnitRPM = "rpm"
+ NativeSensorStatusOK = "ok"
+ NativeSensorStatusInvalid = "invalid"
+)
+
+// NativeSensor is one lm-sensors temperature or fan input as the host
+// reported it. ID is "<chip>/<channel>" (for example
+// "applesmc-isa-0300/temp1"): the full chip name with its bus address plus
+// the canonical input channel. It is a host-scoped source key that keeps chips
+// of one type, and labels that differ only by case, apart, and stays the same
+// while the kernel enumerates the chip the same way; it is not a
+// physical-device identity. Label is the chip's original feature name. Value
+// is the Celsius or RPM lm-sensors reported, unconverted, and is omitted when
+// the chip returned no finite number. An invalid status marks a reading
+// outside the plausible range, such as -127 °C from an unattached SMC input;
+// the server recomputes it on ingest. This inventory sits beside the legacy
+// TemperatureCelsius, FanRPM and Additional maps, which keep their existing
+// keys and filtering.
+type NativeSensor struct {
+ ID string `json:"id"`
+ Chip string `json:"chip"`
+ Adapter string `json:"adapter,omitempty"`
+ Channel string `json:"channel"`
+ Label string `json:"label"`
+ Kind string `json:"kind"`
+ Unit string `json:"unit"`
+ Value *float64 `json:"value,omitempty"`
+ Status string `json:"status"`
+}
+
// GPUSensor captures direct GPU telemetry reported by a local host agent.
type GPUSensor struct {
ID string `json:"id,omitempty"`
diff --git a/pkg/agents/host/report_test.go b/pkg/agents/host/report_test.go
index c87df049a8..82a850d57e 100644
--- a/pkg/agents/host/report_test.go
+++ b/pkg/agents/host/report_test.go
@@ -2,6 +2,8 @@ package host
import (
"encoding/json"
+ "reflect"
+ "strings"
"testing"
"time"
@@ -184,6 +186,39 @@ func TestCustomSensorMetricJSONRoundTrip(t *testing.T) {
}
}
+func TestNativeSensorJSONRoundTrip(t *testing.T) {
+ value := 34.2
+ original := Sensors{Native: []NativeSensor{
+ {ID: "applesmc-isa-0300/temp1", Chip: "applesmc-isa-0300", Adapter: "ISA adapter", Channel: "temp1", Label: "TB0T",
+ Kind: NativeSensorKindTemperature, Unit: NativeSensorUnitCelsius, Value: &value, Status: NativeSensorStatusOK},
+ {ID: "applesmc-isa-0300/temp9", Chip: "applesmc-isa-0300", Channel: "temp9", Label: "Probe",
+ Kind: NativeSensorKindTemperature, Unit: NativeSensorUnitCelsius, Status: NativeSensorStatusInvalid},
+ }}
+ data, err := json.Marshal(original)
+ if err != nil {
+ t.Fatalf("marshal native sensors: %v", err)
+ }
+ if !strings.Contains(string(data), `"native":[{"id":"applesmc-isa-0300/temp1","chip":"applesmc-isa-0300","adapter":"ISA adapter","channel":"temp1","label":"TB0T","kind":"temperature","unit":"celsius","value":34.2,"status":"ok"}`) {
+ t.Fatalf("native sensor wire format changed: %s", data)
+ }
+ var decoded Sensors
+ if err := json.Unmarshal(data, &decoded); err != nil {
+ t.Fatalf("unmarshal native sensors: %v", err)
+ }
+ if !reflect.DeepEqual(decoded, original) {
+ t.Fatalf("native sensors did not round trip: %+v", decoded)
+ }
+
+ // A report from an agent that predates the inventory has no native field.
+ var legacy Sensors
+ if err := json.Unmarshal([]byte(`{"additional":{"applesmc_tb0t":34.2}}`), &legacy); err != nil {
+ t.Fatalf("unmarshal legacy sensors: %v", err)
+ }
+ if legacy.Native != nil || legacy.Additional["applesmc_tb0t"] != 34.2 {
+ t.Fatalf("legacy sensors = %+v, want no inventory and the additional reading", legacy)
+ }
+}
+
// The privilege block is agent-authored fact, not configuration: it must
// survive a JSON round trip exactly, and a legacy report without it must
// decode to nil rather than a zero-value profile pretending to be evidence.