Skip to content

Commit

Permalink
Do not use psutil virtual_memory used/free: not reliable. Use total/a…
Browse files Browse the repository at this point in the history
…vailable instead
  • Loading branch information
mathoudebine committed Jan 28, 2024
1 parent ebc32cd commit c3257df
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions library/sensors/sensors_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,15 @@ def virtual_percent() -> float:

@staticmethod
def virtual_used() -> int: # In bytes
return psutil.virtual_memory().used
# Do not use psutil.virtual_memory().used: from https://psutil.readthedocs.io/en/latest/#memory
# "It is calculated differently depending on the platform and designed for informational purposes only"
return psutil.virtual_memory().total - psutil.virtual_memory().available

@staticmethod
def virtual_free() -> int: # In bytes
return psutil.virtual_memory().free
# Do not use psutil.virtual_memory().free: from https://psutil.readthedocs.io/en/latest/#memory
# "note that this doesn’t reflect the actual memory available (use available instead)."
return psutil.virtual_memory().available


class Disk(sensors.Disk):
Expand Down

0 comments on commit c3257df

Please sign in to comment.