From 4dbd81b352927d6afa5a591e6a06d883e8246b94 Mon Sep 17 00:00:00 2001 From: saqriphnix Date: Sat, 27 Jul 2024 19:16:40 +0300 Subject: [PATCH] RAM percentage recording. removed unnecessary sensors --- misc/sensors.py | 7 +++++-- prettyprint.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/misc/sensors.py b/misc/sensors.py index c416771..c6d55bd 100644 --- a/misc/sensors.py +++ b/misc/sensors.py @@ -22,6 +22,7 @@ class CpuSensor: @dataclass class RamSensor: current_avail: int + current_avail_percentage: float warning_avail: int = 4 * 1024**3 critical_avail: int = 2 * 1024**3 @@ -69,7 +70,7 @@ class Sensors: # skipping first 8 elements as they're not informative # while the last elements duplicate the first ones, # but with more understandable names - for sensor in sensors[7::]: + for sensor in sensors[7:-2:]: temp_sensors[s_type].append( TemperatureSensor( sensor_type=s_type, @@ -88,7 +89,9 @@ class Sensors: @staticmethod def get_ram() -> RamSensor: - return RamSensor(current_avail=virtual_memory().available) + ram = virtual_memory() + return RamSensor(current_avail=ram.available, + current_avail_percentage=ram.percent) if __name__ == "__main__": diff --git a/prettyprint.py b/prettyprint.py index 8867d78..0cdf5ef 100755 --- a/prettyprint.py +++ b/prettyprint.py @@ -18,7 +18,7 @@ def pretty_print(): s = Sensors.get_cpu() print(f"Used CPU: {s.current_load}%") s = Sensors.get_ram() - print(f"Available RAM: {(s.current_avail / 1024**3):.2f} GiB") + print(f"Available RAM: {(s.current_avail / 1024**3):.2f} ({s.current_avail_percentage}%) GiB") if __name__ == "__main__":