@@ -381,28 +381,31 @@ def is_available(cls) -> bool:
381381class Memory (sensors .Memory ):
382382 @staticmethod
383383 def swap_percent () -> float :
384- memory = get_hw_and_update (Hardware .HardwareType .Memory )
384+ ram = get_hw_and_update (Hardware .HardwareType .Memory , "Total Memory" )
385+ vram = get_hw_and_update (Hardware .HardwareType .Memory , "Virtual Memory" )
385386
386387 virtual_mem_used = math .nan
387388 mem_used = math .nan
388389 virtual_mem_available = math .nan
389390 mem_available = math .nan
390391
391392 # Get virtual / physical memory stats
392- for sensor in memory .Sensors :
393+ for sensor in ram .Sensors :
393394 if sensor .SensorType == Hardware .SensorType .Data and str (sensor .Name ).startswith (
394- "Virtual Memory Used" ) and sensor .Value is not None :
395- virtual_mem_used = int (sensor .Value )
396- elif sensor .SensorType == Hardware .SensorType .Data and str (sensor .Name ).startswith (
397395 "Memory Used" ) and sensor .Value is not None :
398396 mem_used = int (sensor .Value )
399- elif sensor .SensorType == Hardware .SensorType .Data and str (sensor .Name ).startswith (
400- "Virtual Memory Available" ) and sensor .Value is not None :
401- virtual_mem_available = int (sensor .Value )
402397 elif sensor .SensorType == Hardware .SensorType .Data and str (sensor .Name ).startswith (
403398 "Memory Available" ) and sensor .Value is not None :
404399 mem_available = int (sensor .Value )
405400
401+ for sensor in vram .Sensors :
402+ if sensor .SensorType == Hardware .SensorType .Data and str (sensor .Name ).startswith (
403+ "Memory Used" ) and sensor .Value is not None :
404+ virtual_mem_used = int (sensor .Value )
405+ elif sensor .SensorType == Hardware .SensorType .Data and str (sensor .Name ).startswith (
406+ "Memory Available" ) and sensor .Value is not None :
407+ virtual_mem_available = int (sensor .Value )
408+
406409 # Compute swap stats from virtual / physical memory stats
407410 swap_used = virtual_mem_used - mem_used
408411 swap_available = virtual_mem_available - mem_available
@@ -417,8 +420,8 @@ def swap_percent() -> float:
417420
418421 @staticmethod
419422 def virtual_percent () -> float :
420- memory = get_hw_and_update (Hardware .HardwareType .Memory )
421- for sensor in memory .Sensors :
423+ ram = get_hw_and_update (Hardware .HardwareType .Memory , "Total Memory" )
424+ for sensor in ram .Sensors :
422425 if sensor .SensorType == Hardware .SensorType .Load and str (sensor .Name ).startswith (
423426 "Memory" ) and sensor .Value is not None :
424427 return float (sensor .Value )
@@ -427,8 +430,8 @@ def virtual_percent() -> float:
427430
428431 @staticmethod
429432 def virtual_used () -> int : # In bytes
430- memory = get_hw_and_update (Hardware .HardwareType .Memory )
431- for sensor in memory .Sensors :
433+ ram = get_hw_and_update (Hardware .HardwareType .Memory , "Total Memory" )
434+ for sensor in ram .Sensors :
432435 if sensor .SensorType == Hardware .SensorType .Data and str (sensor .Name ).startswith (
433436 "Memory Used" ) and sensor .Value is not None :
434437 return int (sensor .Value * 1000000000.0 )
@@ -437,8 +440,8 @@ def virtual_used() -> int: # In bytes
437440
438441 @staticmethod
439442 def virtual_free () -> int : # In bytes
440- memory = get_hw_and_update (Hardware .HardwareType .Memory )
441- for sensor in memory .Sensors :
443+ ram = get_hw_and_update (Hardware .HardwareType .Memory , "Total Memory" )
444+ for sensor in ram .Sensors :
442445 if sensor .SensorType == Hardware .SensorType .Data and str (sensor .Name ).startswith (
443446 "Memory Available" ) and sensor .Value is not None :
444447 return int (sensor .Value * 1000000000.0 )
0 commit comments