From ea4675a56ccf2506d099696f340966ca6d6aeaac Mon Sep 17 00:00:00 2001 From: Shailaja Date: Fri, 28 Jun 2024 18:12:11 +0530 Subject: [PATCH] updated get_ram_and_disk method --- agent.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/agent.py b/agent.py index f072ee8..4c6a7fb 100644 --- a/agent.py +++ b/agent.py @@ -145,13 +145,14 @@ class ServerData: for device in os.listdir('/sys/block'): device_path = '/sys/block/{}/device'.format(device) size_path = '/sys/block/{}/size'.format(device) - if os.path.islink(device_path): - try: - with open(size_path, 'r') as f: - size = int(f.read().strip()) - disk += size - except Exception: - pass # Skip the device if any exception occurs + if not os.path.islink(device_path): + continue + try: + with open(size_path, 'r') as f: + size = int(f.read().strip()) + disk += size + except Exception: + pass disk = disk * 512 // (1024**3) # convert to GB logging.info("RAM: {}MB, Disk: {}GB".format(ram, disk)) -- 2.45.1