Skip to content

Instantly share code, notes, and snippets.

@guiszk
Created October 19, 2021 15:35
Show Gist options
  • Save guiszk/0ee4c7e6f46be1540f9bab54d90255c1 to your computer and use it in GitHub Desktop.
Save guiszk/0ee4c7e6f46be1540f9bab54d90255c1 to your computer and use it in GitHub Desktop.
Get system information with Python
import psutil
fan = psutil.disk_usage(path="/")
print("[DISK]")
print("Available: ", fan.total/1000000000, "GB")
print("Used: ", fan.used/1000000000, "GB")
print("Free: ", fan.free/1000000000, "GB")
print("Percentage Used: ", fan.percent, "%")
mem = psutil.virtual_memory()
print("[MEMORY]")
print("Available: ", mem.total/1000000000, "GB")
print("Used: ", mem.used/1000000000, "GB")
print("Free: ", mem.free/1000000000, "GB")
print("Percentage Used: ", mem.percent, "%")
"""example output:
[DISK]
Available: 250.790436864 GB
Used: 23.998644224 GB
Free: 45.549592576 GB
Percentage Used: 34.5 %
[MEMORY]
Available: 8.589934592 GB
Used: 4.75119616 GB
Free: 0.02410496 GB
Percentage Used: 71.4 %
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment