Last active
November 15, 2015 12:28
-
-
Save bmwant/6760ebb3571a1ca9b02b to your computer and use it in GitHub Desktop.
Get some OS info with psutils
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 os | |
import time | |
import psutil | |
import humanfriendly | |
now = time.time() | |
pid = os.getgid() | |
ppid = os.getppid() | |
current_process = psutil.Process(pid=ppid) | |
process_uptime = current_process.create_time() | |
process_uptime_delta = now - process_uptime | |
process_uptime_human = humanfriendly.format_timespan(process_uptime_delta) | |
system_uptime = psutil.boot_time() | |
system_uptime_delta = now - system_uptime | |
system_uptime_human = humanfriendly.format_timespan(system_uptime_delta) | |
free_memory = psutil.disk_usage('/').free | |
total_memory = psutil.disk_usage('/').total | |
percent_used_memory = psutil.disk_usage('/').percent | |
used_memory = psutil.disk_usage('/').used | |
free_memory_human = humanfriendly.format_size(free_memory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment