forked from Sysdeploy/idlers-agent
disk space calculation using /sys/block/
This commit is contained in:
parent
1021fdb0e1
commit
a502498394
36
agent.py
36
agent.py
|
@ -28,26 +28,26 @@ class ServerData:
|
|||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
def get_ram_and_disk(self):
|
||||
# RAM information
|
||||
with open('/proc/meminfo', 'r') as f:
|
||||
meminfo = f.read()
|
||||
ram = int([x for x in meminfo.split('\n') if 'MemTotal' in x][0].split()[1]) // 1024
|
||||
# RAM information
|
||||
with open('/proc/meminfo', 'r') as f:
|
||||
meminfo = f.read()
|
||||
ram = int([x for x in meminfo.split('\n') if 'MemTotal' in x][0].split()[1]) // 1024
|
||||
|
||||
# Disk space information
|
||||
disk = 0
|
||||
for device in os.listdir('/sys/block'):
|
||||
size_path = f'/sys/block/{device}/size'
|
||||
if os.path.exists(size_path) and os.access(size_path, os.R_OK):
|
||||
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
|
||||
# Disk space information
|
||||
disk = 0
|
||||
for device in os.listdir('/sys/block'):
|
||||
size_path = f'/sys/block/{device}/size'
|
||||
if os.path.exists(size_path) and os.access(size_path, os.R_OK):
|
||||
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
|
||||
|
||||
disk = disk * 512 // (1024**3) # convert to GB
|
||||
logging.info(f"RAM: {ram}MB, Disk: {disk}GB")
|
||||
return ram, disk
|
||||
disk = disk * 512 // (1024**3) # convert to GB
|
||||
logging.info(f"RAM: {ram}MB, Disk: {disk}GB")
|
||||
return ram, disk
|
||||
|
||||
def get_cpu_count(self):
|
||||
cpu_count = 0
|
||||
|
|
Loading…
Reference in New Issue
Block a user