Created
April 27, 2020 07:44
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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