From ea74b0272ee83e0a7f5f0f243d2bfa5f85efde51 Mon Sep 17 00:00:00 2001 From: Tobias Schneider Date: Sat, 13 Mar 2021 22:53:06 +0100 Subject: [PATCH] Extended montioring functionality --- monitor.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/monitor.py b/monitor.py index 377d7dc..76251ea 100755 --- a/monitor.py +++ b/monitor.py @@ -33,10 +33,14 @@ def parse_top_string(data): ram_unit, ram_data = rows[2].split(':', 2) ram_factor = 1 if ram_unit[0] == 'K': + ram_factor = 1024 * 1024 + elif ram_unit[0] == 'M': ram_factor = 1024 + elif ram_unit[0] == 'G': + ram_factor = 1 ram_data = ram_data.strip().split(',') - ram_total = float(ram_data[0].strip().split(' ', 2)[0].strip()) / ram_factor / 1024 - ram_free = float(ram_data[1].strip().split(' ', 2)[0].strip()) / ram_factor / 1024 + ram_total = float(ram_data[0].strip().split(' ', 2)[0].strip()) / ram_factor + ram_free = float(ram_data[1].strip().split(' ', 2)[0].strip()) / ram_factor return load, cpu_percent, ram_total, ram_free