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.

Supplement unusable CPU sensor output from sysfs

pulse-triage[bot]b5360c1e5a9e
diff --git a/internal/sensors/collector.go b/internal/sensors/collector.go
index 894900e28e..57391caca7 100644
--- a/internal/sensors/collector.go
+++ b/internal/sensors/collector.go
@@ -28,8 +28,9 @@ var (
)
// CollectLocal reads lm-sensors JSON and supplements it with a recognised CPU
-// thermal sysfs source when it contains no CPU chip. Other lm-sensors readings
-// are retained; sysfs is also used when lm-sensors is unavailable or empty.
+// thermal sysfs source when it contains no usable CPU temperature. Other
+// lm-sensors readings are retained; sysfs is also used when lm-sensors is
+// unavailable or empty.
func CollectLocal(ctx context.Context) (string, error) {
ctx = normalizeCollectionContext(ctx)
@@ -69,17 +70,16 @@ func CollectLocal(ctx context.Context) (string, error) {
}
// addMissingSysfsCPU leaves existing output unchanged unless it is a JSON
-// object without a recognised CPU chip and an identified sysfs source is
+// object without a usable CPU reading and an identified sysfs source is
// available. A failed optional lookup must not discard working sensors data.
func addMissingSysfsCPU(ctx context.Context, sensorsJSON string) string {
var chips map[string]json.RawMessage
if err := json.Unmarshal([]byte(sensorsJSON), &chips); err != nil || chips == nil {
return sensorsJSON
}
- for name := range chips {
- if isCPUChip(strings.ToLower(name)) {
- return sensorsJSON
- }
+ parsed, err := Parse(sensorsJSON)
+ if err != nil || parsed.CPUPackage > 0 {
+ return sensorsJSON
}
fallbackJSON, err := collectSysfsCPUTemperature(ctx)
if err != nil {
diff --git a/internal/sensors/collector_additional_test.go b/internal/sensors/collector_additional_test.go
index 90f75da625..4f55322c9e 100644
--- a/internal/sensors/collector_additional_test.go
+++ b/internal/sensors/collector_additional_test.go
@@ -101,6 +101,27 @@ func TestCollectLocal_SensorsJSONGainsMissingSysfsCPU(t *testing.T) {
}
}
+func TestCollectLocal_CPUChipWithoutTemperatureGainsSysfsCPU(t *testing.T) {
+ dir := t.TempDir()
+ const original = `{"armada_thermal-virtual-0":{"temp1":{"temp1_input":"bad"}},"nvme-pci-0100":{"Composite":{"temp1_input":39}}}`
+ writeScript(t, dir, "sensors", "#!/bin/sh\necho '"+original+"'\n")
+ t.Setenv("PATH", dir+":"+os.Getenv("PATH"))
+ thermal, _ := useTestSysfsRoots(t)
+ writeSysfsSensor(t, thermal, "thermal_zone0", "type", "armada_thermal", "57000")
+
+ out, err := CollectLocal(context.Background())
+ if err != nil {
+ t.Fatal(err)
+ }
+ parsed, err := Parse(out)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if parsed.CPUPackage != 57 || parsed.NVMe["nvme0"] != 39 {
+ t.Fatalf("unusable CPU chip blocked sysfs or lost lm-sensors data: %+v", parsed)
+ }
+}
+
func TestCollectLocal_ExistingCPUPrecedesSysfs(t *testing.T) {
dir := t.TempDir()
const original = `{"coretemp-isa-0000":{"Package id 0":{"temp1_input":42}}}`