Move original monitor program

This commit is contained in:
Jeff Curless
2025-10-12 23:16:01 -04:00
parent 542cdecab3
commit fcb9b0ca76

View File

@@ -42,9 +42,9 @@ class DriveStat:
FLUSH_TICKS = 16 FLUSH_TICKS = 16
def __init__( self, device:str ): def __init__( self, device:str ):
self.last = [] self._last : list[int] = []
self.stats = [] self._stats : list[int] = []
self.device = device self._device = device
self._readStats() self._readStats()
def _readStats( self ): def _readStats( self ):
@@ -57,12 +57,12 @@ class DriveStat:
''' '''
try: try:
self.last = self.stats self._last = self._stats
with open( f"/sys/block/{self.device}/stat", "r") as f: with open( f"/sys/block/{self._device}/stat", "r") as f:
stats = f.readline().strip().split(" ") curStats = f.readline().strip().split(" ")
self.stats = [int(l) for l in stats if l] self._stats = [int(l) for l in curStats if l]
except Exception as e: except Exception as e:
print( f"Failure reading disk statistics for {device} error {e}" ) print( f"Failure reading disk statistics for {self._device} error {e}" )
def _getStats( self ) -> list[int]: def _getStats( self ) -> list[int]:
''' '''
@@ -71,12 +71,14 @@ class DriveStat:
Returns: Returns:
An array containing all of the data colleected about the device. An array containing all of the data colleected about the device.
''' '''
curData : list[int] = []
self._readStats() self._readStats()
if self.last == []: if self._last == []:
data = self.stats[:] curData = self._stats[:]
else: else:
data = [ d-self.last[i] for i,d in enumerate( self.stats ) ] curData = [ d-self._last[i] for i,d in enumerate( self._stats ) ]
return data return curData
def readAllStats( self ) -> list[int]: def readAllStats( self ) -> list[int]:
''' '''
@@ -96,9 +98,9 @@ class DriveStat:
def discardSectors( self ) -> int: def discardSectors( self ) -> int:
return self._getStats()[DriveStat.DISCARD_SECTORS] return self._getStats()[DriveStat.DISCARD_SECTORS]
def readWriteSectors( self ) -> (int,int): def readWriteSectors( self ) -> tuple[int,int]:
data = self._getStats() curData = self._getStats()
return (data[DriveStat.READ_SECTORS],data[DriveStat.WRITE_SECTORS]) return (curData[DriveStat.READ_SECTORS],curData[DriveStat.WRITE_SECTORS])
def setupTemperatureObject(): def setupTemperatureObject():
@@ -112,13 +114,13 @@ def setupTemperatureObject():
Return: Return:
A CPU temperature object A CPU temperature object
''' '''
cpuTemp = None cpuTempObj = None
try: try:
cpuTemp = CPUTemperature() cpuTempObj = CPUTemperature()
except Exception as error: except Exception as error:
log.error( f"Error creating CPU temperature object, error is {error}" ) print( f"Error creating CPU temperature object, error is {error}" )
return cpuTemp return cpuTempObj
def getFanSpeed() -> int: def getFanSpeed() -> int:
''' '''
@@ -131,10 +133,10 @@ def getFanSpeed() -> int:
fanSpeed = 0 fanSpeed = 0
try: try:
command = os.popen( 'cat /sys/devices/platform/cooling_fan/hwmon/*/fan1_input' ) command = os.popen( 'cat /sys/devices/platform/cooling_fan/hwmon/*/fan1_input' )
fanSpeed = command.read().strip() fanSpeed = int(command.read().strip())
except: except:
pass pass
return int(fanSpeed) return fanSpeed
def getNVMETemp(device : str) -> float: def getNVMETemp(device : str) -> float:
''' '''
@@ -147,11 +149,13 @@ def getNVMETemp(device : str) -> float:
The temperature as a float The temperature as a float
''' '''
smartOutRaw = "" smartOutRaw = ""
cmd = f'smartctl -A /dev/{device}'
try: try:
command = os.popen( f'smartctl -A /dev/{device}' ) command = os.popen( cmd )
smartOutRaw = command.read() smartOutRaw = command.read()
except Exception as e: except Exception as error:
return 0 print( f"Could not launch {cmd} error is {error}" )
return 0.0
finally: finally:
command.close() command.close()
@@ -169,12 +173,10 @@ def getNVMETemp(device : str) -> float:
return float(0.0) return float(0.0)
def argonsysinfo_kbstr(kbval, wholenumbers = True): def argonsysinfo_kbstr(kbval):
remainder = 0
suffixidx = 0 suffixidx = 0
suffixlist = ["B","KiB", "MiB", "GiB", "TiB"] suffixlist = ["B","KiB", "MiB", "GiB", "TiB"]
while kbval > 1023 and suffixidx < len(suffixlist): while kbval > 1023 and suffixidx < len(suffixlist):
remainder = kbval % 1024
kbval = kbval // 1024 kbval = kbval // 1024
suffixidx = suffixidx + 1 suffixidx = suffixidx + 1
return f"{kbval} {suffixlist[suffixidx]}" return f"{kbval} {suffixlist[suffixidx]}"
@@ -191,4 +193,4 @@ while True:
data = stats.readWriteSectors() data = stats.readWriteSectors()
print( f"Read : {argonsysinfo_kbstr(data[0]*512)}/s" ) print( f"Read : {argonsysinfo_kbstr(data[0]*512)}/s" )
print( f"Write: {argonsysinfo_kbstr(data[1]*512)}/s" ) print( f"Write: {argonsysinfo_kbstr(data[1]*512)}/s" )
time.sleep(1) time.sleep(1)