Compare commits

..

3 Commits

Author SHA1 Message Date
75744e0010
Get nvme devices inside /sys/block/ instead of /dev 2024-07-01 18:15:53 +05:30
2c19f2eefc
Added nvme details 2024-07-01 18:15:52 +05:30
ea4675a56c
updated get_ram_and_disk method 2024-06-28 18:16:49 +05:30

View File

@ -157,7 +157,7 @@ class ServerData:
return devices
# Get the list of nvme devices starting with 'nvme'
nvme_devices = [device for device in os.listdir('/dev') if device.startswith('nvme')]
nvme_devices = [device for device in os.listdir('/sys/block') if device.startswith('nvme')]
for device in nvme_devices:
device_path = '/dev/' + device
@ -193,13 +193,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):
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 # Skip the device if any exception occurs
pass
disk = disk * 512 // (1024**3) # convert to GB
logging.info("RAM: {}MB, Disk: {}GB".format(ram, disk))