forked from Sysdeploy/idlers-agent
Compare commits
1 Commits
217e433f76
...
c0d919ce2c
Author | SHA1 | Date | |
---|---|---|---|
c0d919ce2c |
16
agent.py
16
agent.py
|
@ -28,12 +28,22 @@ class ServerData:
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
def get_ram_and_disk(self):
|
def get_ram_and_disk(self):
|
||||||
|
# RAM information
|
||||||
with open('/proc/meminfo', 'r') as f:
|
with open('/proc/meminfo', 'r') as f:
|
||||||
meminfo = f.read()
|
meminfo = f.read()
|
||||||
ram = int([x for x in meminfo.split('\n') if 'MemTotal' in x][0].split()[1]) // 1024
|
ram = int([x for x in meminfo.split('\n') if 'MemTotal' in x][0].split()[1]) // 1024
|
||||||
with open('/proc/diskstats', 'r') as f:
|
|
||||||
diskstats = f.read()
|
# Disk space information
|
||||||
disk = sum(int(x.split()[9]) for x in diskstats.split('\n') if x) * 512 // 10**9
|
disk = 0
|
||||||
|
for device in os.listdir('/sys/block'):
|
||||||
|
try:
|
||||||
|
with open(f'/sys/block/{device}/size', 'r') as f:
|
||||||
|
size = int(f.read().strip())
|
||||||
|
disk += size
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Failed to read disk size for {device}: {e}")
|
||||||
|
|
||||||
|
disk = disk * 512 // (1024**3) # convert to GB
|
||||||
logging.info(f"RAM: {ram}MB, Disk: {disk}GB")
|
logging.info(f"RAM: {ram}MB, Disk: {disk}GB")
|
||||||
return ram, disk
|
return ram, disk
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user