From c3257df15c242fd9cfe0888f301146b1353088a4 Mon Sep 17 00:00:00 2001 From: Matthieu Houdebine Date: Sun, 28 Jan 2024 23:21:31 +0100 Subject: [PATCH] Do not use psutil virtual_memory used/free: not reliable. Use total/available instead --- library/sensors/sensors_python.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/sensors/sensors_python.py b/library/sensors/sensors_python.py index 51a62841..d60fc7d9 100644 --- a/library/sensors/sensors_python.py +++ b/library/sensors/sensors_python.py @@ -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):