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.

Fix Proxmox SMART disk temperature collection

rcourtmancf7524d06aaa
diff --git a/internal/api/config_handlers_setup_script_test.go b/internal/api/config_handlers_setup_script_test.go
index 4c570d6c1a..44e7254355 100644
--- a/internal/api/config_handlers_setup_script_test.go
+++ b/internal/api/config_handlers_setup_script_test.go
@@ -176,6 +176,10 @@ func TestPVESetupScriptRestrictsTemperatureMonitoringToPulseSensorWrapper(t *tes
required := []string{
`PULSE_SENSORS_WRAPPER="/usr/local/sbin/pulse-sensors"`,
`install_pulse_sensors_wrapper() {`,
+ `def block_device_targets():`,
+ `["lsblk", "-J", "-d", "-o", "NAME,TYPE,TRAN,MODEL,VENDOR,SUBSYSTEMS"]`,
+ `def union_smart_targets(scan_targets, block_devices):`,
+ `def smart_probe_attempts(device, device_type):`,
`"smart": collect_smart(),`,
`SSH_SENSORS_KEY_ENTRY="command=\"$PULSE_SENSORS_WRAPPER\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty $SSH_SENSORS_PUBLIC_KEY # pulse-sensors"`,
}
diff --git a/internal/api/setup_script_render.go b/internal/api/setup_script_render.go
index e50db49422..b1e44d6849 100644
--- a/internal/api/setup_script_render.go
+++ b/internal/api/setup_script_render.go
@@ -884,44 +884,150 @@ def smartctl_path():
return shutil.which("smartctl")
-def smart_targets(path):
- result = run_command([path, "--scan-open"])
+def is_multiplexed_device_type(device_type):
+ return bool(device_type and re.search(r",\d", device_type))
+
+
+def nvme_namespace_for_controller(name):
+ if not re.fullmatch(r"nvme\d+", name or ""):
+ return ""
+ try:
+ for candidate in sorted(os.listdir("/sys/block")):
+ if candidate.startswith(name + "n"):
+ return candidate
+ except Exception:
+ return ""
+ return ""
+
+
+def canonical_block_for_device(device):
+ name = os.path.basename(str(device or "").strip())
+ if not name:
+ return ""
+ if re.fullmatch(r"nvme\d+", name):
+ return nvme_namespace_for_controller(name) or name
+ return name
+
+
+def is_physical_block_device(device):
+ name = str(device.get("name") or "").strip()
+ dtype = str(device.get("type") or "").strip().lower()
+ if not name or dtype != "disk":
+ return False
+
+ lowered_name = name.lower()
+ virtual_prefixes = (
+ "loop", "ram", "zram", "dm-", "md", "nbd", "rbd", "sr", "fd",
+ "zd", "vd", "xvd",
+ )
+ if lowered_name.startswith(virtual_prefixes):
+ return False
+
+ metadata = " ".join(
+ str(device.get(key) or "").lower()
+ for key in ("tran", "model", "vendor", "subsystems")
+ )
+ virtual_tokens = ("virtual", "virtio", "qemu", "vmware", "/virtual/")
+ return not any(token in metadata for token in virtual_tokens)
+
+
+def block_device_targets():
+ result = run_command(["lsblk", "-J", "-d", "-o", "NAME,TYPE,TRAN,MODEL,VENDOR,SUBSYSTEMS"])
if not result or not result.stdout.strip():
return []
+ try:
+ data = json.loads(result.stdout)
+ except Exception:
+ return []
- targets = []
+ devices = []
seen = set()
- typed_by_path = set()
- for raw_line in result.stdout.splitlines():
- line = raw_line.split("#", 1)[0].strip()
- if not line:
+ for device in data.get("blockdevices") or []:
+ if not isinstance(device, dict) or not is_physical_block_device(device):
continue
- try:
- fields = shlex.split(line)
- except ValueError:
- fields = line.split()
- if not fields:
+ name = str(device.get("name") or "").strip()
+ if not name or name in seen:
continue
+ seen.add(name)
+ devices.append("/dev/" + name)
+ return devices
- device = fields[0].strip()
- if not device.startswith("/"):
- continue
- device_type = ""
- for idx, field in enumerate(fields[:-1]):
- if field == "-d":
- device_type = fields[idx + 1].strip()
- break
+def union_smart_targets(scan_targets, block_devices):
+ targets = []
+ seen_targets = set()
+ covered_blocks = set()
+ for device, device_type in scan_targets:
key = (device, device_type)
- if key in seen:
+ if key in seen_targets:
+ continue
+ seen_targets.add(key)
+ targets.append(key)
+ if not is_multiplexed_device_type(device_type):
+ block = canonical_block_for_device(device)
+ if block:
+ covered_blocks.add(block)
+
+ for device in block_devices:
+ block = canonical_block_for_device(device)
+ if not block or block in covered_blocks:
+ continue
+ key = ("/dev/" + block, "")
+ if key in seen_targets:
continue
- seen.add(key)
- if device_type:
- typed_by_path.add(device)
+ seen_targets.add(key)
targets.append(key)
+ covered_blocks.add(block)
- return [(device, dtype) for device, dtype in targets if dtype or device not in typed_by_path]
+ return targets
+
+
+def smart_targets(path):
+ result = run_command([path, "--scan-open"])
+
+ targets = []
+ seen = set()
+ typed_by_path = set()
+ if result and result.stdout.strip():
+ for raw_line in result.stdout.splitlines():
+ line = raw_line.split("#", 1)[0].strip()
+ if not line:
+ continue
+ try:
+ fields = shlex.split(line)
+ except ValueError:
+ fields = line.split()
+ if not fields:
+ continue
+
+ device = fields[0].strip()
+ if not device.startswith("/"):
+ continue
+
+ device_type = ""
+ for idx, field in enumerate(fields[:-1]):
+ if field == "-d":
+ device_type = fields[idx + 1].strip()
+ break
+
+ key = (device, device_type)
+ if key in seen:
+ continue
+ seen.add(key)
+ if device_type:
+ typed_by_path.add(device)
+ targets.append(key)
+
+ scan_targets = [(device, dtype) for device, dtype in targets if dtype or device not in typed_by_path]
+ return union_smart_targets(scan_targets, block_device_targets())
+
+
+def smart_probe_attempts(device, device_type):
+ attempts = [(device, device_type)] if device_type else [(device, "")]
+ if device_type and not is_multiplexed_device_type(device_type):
+ attempts.append((device, ""))
+ return attempts
def disk_type(data):
@@ -1022,31 +1128,47 @@ def collect_smart():
entries = []
observed_at = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
for device, device_type in smart_targets(path):
- args = [path]
- if device_type:
- args.extend(["-d", device_type])
- args.extend(["-n", "standby,3", "-i", "-A", "-H", "--json=o", device])
-
- result = run_command(args)
- if not result or not result.stdout.strip():
- continue
- try:
- data = json.loads(result.stdout)
- except Exception:
- continue
+ best_entry = None
+ for attempt_device, attempt_type in smart_probe_attempts(device, device_type):
+ args = [path]
+ if attempt_type:
+ args.extend(["-d", attempt_type])
+ args.extend(["-n", "standby,3", "-i", "-A", "-H", "--json=o", attempt_device])
+
+ result = run_command(args)
+ if not result or not result.stdout.strip():
+ continue
+ try:
+ data = json.loads(result.stdout)
+ except Exception:
+ continue
+
+ power_mode = str(data.get("power_mode") or "").lower()
+ reported_device = attempt_device
+ if is_multiplexed_device_type(attempt_type):
+ reported_device = f"{attempt_device} [{attempt_type}]"
+ else:
+ block = canonical_block_for_device(attempt_device)
+ if block:
+ reported_device = "/dev/" + block
+
+ entry = {
+ "device": reported_device,
+ "model": str(data.get("model_name") or data.get("model_family") or "").strip(),
+ "serial": str(data.get("serial_number") or "").strip(),
+ "wwn": format_wwn(data),
+ "type": disk_type(data),
+ "temperature": smart_temperature(data),
+ "health": smart_health(data),
+ "standbySkipped": "standby" in power_mode or "sleep" in power_mode,
+ "lastUpdated": observed_at,
+ }
+ best_entry = entry
+ if entry["temperature"] > 0 or entry["standbySkipped"] or not attempt_type:
+ break
- power_mode = str(data.get("power_mode") or "").lower()
- entries.append({
- "device": device,
- "model": str(data.get("model_name") or data.get("model_family") or "").strip(),
- "serial": str(data.get("serial_number") or "").strip(),
- "wwn": format_wwn(data),
- "type": disk_type(data),
- "temperature": smart_temperature(data),
- "health": smart_health(data),
- "standbySkipped": "standby" in power_mode or "sleep" in power_mode,
- "lastUpdated": observed_at,
- })
+ if best_entry:
+ entries.append(best_entry)
return entries
diff --git a/internal/monitoring/host_agent_temps.go b/internal/monitoring/host_agent_temps.go
index d0b0db3b4c..cd2de29029 100644
--- a/internal/monitoring/host_agent_temps.go
+++ b/internal/monitoring/host_agent_temps.go
@@ -99,9 +99,11 @@ func (m *Monitor) getHostAgentTemperatureByID(nodeID, nodeName string) *models.T
return m.getClusterSensorTemperature(nodeName)
}
- // Check if the host agent has temperature data
+ // Check if the host agent has temperature data. SMART-only reports are
+ // valid here: some PVE nodes expose no CPU sensor chip but still provide
+ // disk temperatures through the local agent.
sensors := matchedHost.Sensors()
- if sensors == nil || len(sensors.TemperatureCelsius) == 0 {
+ if sensors == nil || (len(sensors.TemperatureCelsius) == 0 && len(sensors.SMART) == 0) {
// Host agent exists but has no temperature data — try cluster cache
return m.getClusterSensorTemperature(nodeName)
}
diff --git a/internal/monitoring/host_agent_temps_test.go b/internal/monitoring/host_agent_temps_test.go
index e8fc59e28d..9c8f309cd9 100644
--- a/internal/monitoring/host_agent_temps_test.go
+++ b/internal/monitoring/host_agent_temps_test.go
@@ -432,6 +432,29 @@ func TestGetHostAgentTemperature(t *testing.T) {
assert.Equal(t, 60.0, result.CPUPackage)
})
+ t.Run("match by linked node id with SMART-only sensors", func(t *testing.T) {
+ host := models.Host{
+ ID: "host-smart-only",
+ LinkedNodeID: "node-smart-only",
+ Sensors: models.HostSensorSummary{
+ SMART: []models.HostDiskSMART{
+ {Device: "/dev/sda", Temperature: 36, Health: "PASSED"},
+ },
+ },
+ LastSeen: time.Now(),
+ }
+ m.state.UpsertHost(host)
+
+ result := m.getHostAgentTemperatureByID("node-smart-only", "different-name")
+ assert.NotNil(t, result)
+ assert.True(t, result.Available)
+ assert.True(t, result.HasSMART)
+ if assert.Len(t, result.SMART, 1) {
+ assert.Equal(t, "/dev/sda", result.SMART[0].Device)
+ assert.Equal(t, 36, result.SMART[0].Temperature)
+ }
+ })
+
t.Run("match by hostname fallback", func(t *testing.T) {
host := models.Host{
ID: "host2",