Make sure the drive temperatures are added

Need to ensure that we add temperatures for each physical drive we add
into the system.
This commit is contained in:
Jeff Curless
2025-10-20 20:46:25 -04:00
parent 9fdd59c424
commit 6c6fe7065a
2 changed files with 37 additions and 9 deletions

View File

@@ -328,23 +328,25 @@ class MonitorWindow(QMainWindow):
exception, so everything needs to be wrapped in a handler. exception, so everything needs to be wrapped in a handler.
''' '''
# Obtain the CPU temperature
try:
cpu_c = float(sysdata.CPUTemperature)
except Exception:
cpu_c = None
# Obtain the current fan speed # Obtain the current fan speed
try: try:
fan_speed = sysdata.fanSpeed fan_speed = sysdata.fanSpeed
except Exception: except Exception:
fan_speed = None fan_speed = None
temperatures = []
try:
temperatures.append( float(sysdata.CPUTemperature) )
except Exception:
temperatures.append( 0.0 )
# Obtain the NVMe device temperature # Obtain the NVMe device temperature
try: try:
nvme_c = sysdata.driveTemp for _drive in multiDrive.drives:
temperatures.append( multiDrive.driveTemp( _drive ) )
except Exception: except Exception:
nvme_c = None temperatures = [ 0.0 for _ in multiDrive.drives ]
# Obtain the NVMe Device read and write rates # Obtain the NVMe Device read and write rates
try: try:
@@ -364,7 +366,7 @@ class MonitorWindow(QMainWindow):
values = [ None for name in cpuload.cpuNames ] values = [ None for name in cpuload.cpuNames ]
# Append to charts # Append to charts
self.cpu_chart.append([cpu_c,nvme_c]) self.cpu_chart.append( temperatures )
self.fan_chart.append([fan_speed]) self.fan_chart.append([fan_speed])
self.io_chart.append( rwData ) self.io_chart.append( rwData )
self.use_chart.append( values ) self.use_chart.append( values )

View File

@@ -191,6 +191,32 @@ class multiDriveStat():
except: except:
return 0 return 0
def driveTemp(self,_drive) -> float:
smartOutRaw = ""
cmd = f'sudo smartctl -A /dev/{_drive}'
try:
command = os.popen( cmd )
smartOutRaw = command.read()
except Exception as error:
print( f"Could not launch {cmd} error is {error}" )
return 0.0
finally:
command.close()
smartOut = [ l for l in smartOutRaw.split('\n') if l]
for smartAttr in ["Temperature:","194","190"]:
try:
line = [l for l in smartOut if l.startswith(smartAttr)][0]
parts = [p for p in line.replace('\t',' ').split(' ') if p]
if smartAttr == "Temperature:":
return float(parts[1])
else:
return float(parts[0])
except IndexError:
pass
return float(0.0)
def readWriteSectors( self )-> dict[str,tuple[int,int]]: def readWriteSectors( self )-> dict[str,tuple[int,int]]:
''' '''
Obtain the number of sectors read and written since the last Obtain the number of sectors read and written since the last