|
1 | | -from colorama import Fore, Style, init |
| 1 | +from colorama import Fore, Style |
2 | 2 | import psutil, time |
3 | | - |
4 | | -init() |
| 3 | +import functions |
5 | 4 |
|
6 | 5 | def gb_calculation(value): |
7 | 6 | return f"{value / (1024 ** 3):.2f}" |
8 | 7 |
|
9 | | -def print_stats(cpu, ram, swap): |
10 | | - print(Fore.YELLOW + "Processer Load: " + Style.RESET_ALL + f'{cpu}%', flush=True) |
11 | | - print(Fore.MAGENTA + "Total RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.total)} GB", flush=True) |
12 | | - print(Fore.MAGENTA + "Available RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.available)} GB", flush=True) |
13 | | - print(Fore.MAGENTA + "Used RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.used)} GB", flush=True) |
14 | | - print(Fore.MAGENTA + "RAM usage percentage: " + Style.RESET_ALL + f'{ram.percent}%', flush=True) |
15 | | - print(Fore.GREEN + "Total Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.total)} GB") |
16 | | - print(Fore.GREEN + "Used Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.used)} GB") |
17 | | - print(Fore.GREEN + "Free Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.free)} GB") |
18 | | - print(Fore.GREEN + "Swap usage percentage: " + Style.RESET_ALL + f"{swap.percent}%") |
19 | | - |
20 | 8 | try: |
21 | 9 | psutil.cpu_percent(interval=1) |
22 | 10 | while True: |
23 | | - c = psutil.cpu_percent(interval=0) |
24 | | - r = psutil.virtual_memory() |
25 | | - s = psutil.swap_memory() |
26 | | - print_stats(c, r, s) |
| 11 | + cpu = psutil.cpu_percent(interval=0) |
| 12 | + ram = psutil.virtual_memory() |
| 13 | + swap = psutil.swap_memory() |
| 14 | + print(Fore.LIGHTYELLOW_EX + "Processer Load: " + Style.RESET_ALL + f'{cpu}%', flush=True) |
| 15 | + print(Fore.LIGHTMAGENTA_EX + "Total RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.total)} GB", flush=True) |
| 16 | + print(Fore.LIGHTMAGENTA_EX + "Available RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.available)} GB", flush=True) |
| 17 | + print(Fore.LIGHTMAGENTA_EX + "Used RAM: " + Style.RESET_ALL + f"{gb_calculation(ram.used)} GB", flush=True) |
| 18 | + print(Fore.LIGHTMAGENTA_EX + "RAM usage percentage: " + Style.RESET_ALL + f'{ram.percent}%', flush=True) |
| 19 | + print(Fore.LIGHTGREEN_EX + "Total Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.total)} GB", flush=True) |
| 20 | + print(Fore.LIGHTGREEN_EX + "Used Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.used)} GB", flush=True) |
| 21 | + print(Fore.LIGHTGREEN_EX + "Free Swap: " + Style.RESET_ALL + f"{gb_calculation(swap.free)} GB", flush=True) |
| 22 | + print(Fore.LIGHTGREEN_EX + "Swap usage percentage: " + Style.RESET_ALL + f"{swap.percent}%", flush=True) |
| 23 | + print("\nPress CMD+C or CTRL+C to exit", flush=True) |
27 | 24 | time.sleep(1) |
28 | | - for _ in range(9): |
29 | | - print('\033[1A\033[2K', end='', flush=True) |
| 25 | + functions.retract_lines(11) |
30 | 26 | except KeyboardInterrupt: |
31 | | - for _ in range(9): |
32 | | - print('\033[1A\033[2K', end='', flush=True) |
33 | | - print("\nExiting...") |
| 27 | + functions.exit_and_retract(11) |
34 | 28 | except Exception as e: |
35 | 29 | print(f"Exception has occured: {e}") |
36 | 30 |
|
0 commit comments