Skip to content

Instantly share code, notes, and snippets.

@amalgjose
Created April 27, 2020 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalgjose/a7c16cede8ff4f78ce22db1925a72374 to your computer and use it in GitHub Desktop.
Save amalgjose/a7c16cede8ff4f78ce22db1925a72374 to your computer and use it in GitHub Desktop.
Simple program to get the CPU, Disk and Memory utilization of Linux operating system.
import psutil
# Get cpu statistics
cpu = str(psutil.cpu_percent()) + '%'
# Calculate memory information
memory = psutil.virtual_memory()
# Convert Bytes to MB (Bytes -> KB -> MB)
available = round(memory.available/1024.0/1024.0,1)
total = round(memory.total/1024.0/1024.0,1)
mem_info = str(available) + 'MB free / ' + str(total) + 'MB total ( ' + str(memory.percent) + '% )'
# Calculate disk information
disk = psutil.disk_usage('/')
# Convert Bytes to GB (Bytes -> KB -> MB -> GB)
free = round(disk.free/1024.0/1024.0/1024.0,1)
total = round(disk.total/1024.0/1024.0/1024.0,1)
disk_info = str(free) + 'GB free / ' + str(total) + 'GB total ( ' + str(disk.percent) + '% )'
print("CPU Info--> ", cpu)
print("Memory Info-->", mem_info)
print("Disk Info-->", disk_info)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment