Created
February 17, 2018 10:12
-
-
Save dkosmari/6bf4235efd754264be5cd5e21f7bc324 to your computer and use it in GitHub Desktop.
More pythonic version
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
#!/bin/env python3 | |
import curses | |
import curses.ascii | |
import datetime | |
import humanize | |
import psutil | |
def main(screen): | |
screen.timeout(1000) | |
curses.curs_set(0) | |
# make sure to use transparent background, if possible | |
curses.use_default_colors() | |
curses.init_pair(1, curses.COLOR_MAGENTA, -1) | |
H1 = curses.color_pair(1) | curses.A_STANDOUT | curses.A_BOLD | |
curses.init_pair(2, curses.COLOR_GREEN, -1) | |
H2 = curses.color_pair(2) | curses.A_BOLD | |
curses.init_pair(3, curses.COLOR_WHITE, -1) | |
H3 = curses.color_pair(3) | |
while True: | |
screen.clear() | |
screen.addstr("++SYSTEM INFO++\n", | |
H1) | |
screen.addstr(" DATE AND TIME\n", | |
H2) | |
time_now = datetime.datetime.now() | |
time_now_rounded = time_now.replace(microsecond=0) | |
screen.addstr(" {}\n\n".format(time_now_rounded), | |
H3) | |
screen.addstr(" UPTIME\n", | |
H2) | |
boot_time = datetime.datetime.fromtimestamp(psutil.boot_time()) | |
boot_time_rounded = boot_time.replace(microsecond=0) | |
uptime = time_now_rounded - boot_time_rounded | |
screen.addstr(" {} ({} s)\n\n".format(uptime, int(uptime.total_seconds())), | |
H3) | |
screen.addstr(" SYSTEM INFO\n", | |
H2 | curses.A_BOLD) | |
sys_info = psutil.os.uname() | |
screen.addstr(" OS: {0.sysname}\n Kernel: {0.release}\n Arch: {0.machine}\n Hostname: {0.nodename}\n\n".format(sys_info), | |
H3) | |
screen.addstr(" CPU INFO\n", | |
H2) | |
screen.addstr(" Cores: {}/{}\n".format(psutil.cpu_count(logical=False), | |
psutil.cpu_count(logical=True)), | |
H3) | |
try: | |
# This method is new in psutil version 5.1.0 | |
cpu_freq = psutil.cpu_freq() | |
screen.addstr(" Min/Max: {0.min}/{0.max} MHz\n".format(cpu_freq), | |
H3) | |
except: | |
pass | |
screen.addstr(" Utilization: {}%\n\n".format(psutil.cpu_percent()), | |
H3) | |
screen.addstr(" MEMORY INFO\n", | |
H2) | |
mem_info = psutil.virtual_memory() | |
screen.addstr(" {0} / {1} ({2:.1%})\n\n".format(humanize.naturalsize(mem_info.used, binary=True), | |
humanize.naturalsize(mem_info.total, binary=True), | |
float(mem_info.used)/mem_info.total), | |
H3) | |
screen.addstr(" PROCESSES\n", | |
H2 | curses.A_BOLD) | |
pid_info = psutil.pids() | |
screen.addstr(" Count: {}".format(len(pid_info)), | |
H3) | |
# quit when pressing ESCAPE or RETURN/ENTER or "Q" | |
key = screen.getch() | |
if key in [27, | |
10, | |
ord("q"), | |
ord("Q")]: | |
break | |
curses.wrapper(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment