.
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | DSM-TUI Documentation
2 |
3 |
4 |
5 | [](#)
6 | [](https://github.com/aniko33/DSM-TUI/releases)
7 | [-orange)](#)
8 |
9 |
10 |
11 | ### Description
12 |
13 | **DSM-TUI** (***Decks Server Manager TUI***) is a **tool** that allows **server
14 | management** by viewing active services and server status. It is developed
15 | in **Python** with **TUI** (***Terminal User Inteface***)
16 |
17 | ### Index
18 |
19 | - [Compatibility](https://github.com/aniko33/DSM-TUI/blob/main/README.md#compatibility)
20 |
21 | - [Platforms](https://github.com/aniko33/DSM-TUI/blob/main/README.md#platforms)
22 |
23 | - [Python version](https://github.com/aniko33/DSM-TUI/blob/main/README.md#python-version)
24 |
25 | - [Download](https://github.com/aniko33/DSM-TUI/blob/main/README.md#download)
26 |
27 | - [From source](https://github.com/aniko33/DSM-TUI/blob/main/README.md#from-source)
28 |
29 | - [From portable file](https://github.com/aniko33/DSM-TUI/blob/main/README.md#from-portable-file)
30 |
31 | - [Usage](https://github.com/aniko33/DSM-TUI/blob/main/README.md#usage)
32 |
33 | - [Notes](https://github.com/aniko33/DSM-TUI/blob/main/README.md#notes)
34 |
35 | - [For users](https://github.com/aniko33/DSM-TUI/blob/main/README.md#for-users)
36 |
37 | - [For Developers](https://github.com/aniko33/DSM-TUI/blob/main/README.md#for-developers)
38 |
39 | - [Screenshot](https://github.com/aniko33/DSM-TUI/blob/main/README.md#screenshot)
40 |
41 | - [Contributors](https://github.com/aniko33/DSM-TUI/blob/main/README.md#Contributors)
42 |
43 | ## Compatibility
44 |
45 | ### Platforms
46 |
47 | #### Available platform: Linux and Windows.
48 |
49 | We made ***Windows compatible*** and ***something in beta could not work***
50 |
51 | ### Python version
52 |
53 | ##### it is recommended to use Python with version "*3*" or higher
54 |
55 | because of the libraries it is better to ***keep version 3*** or **higher** or the **application may not work**.
56 |
57 | ## Download
58 |
59 | ### From source
60 |
61 | **Downloading the app from source** could be both a **bad idea** and a **good idea**, the *app could not go because of the **outdated libraries** or the **outdated program***, instead it could be ***useful in case of problems in the code*** or even just to change it.
62 |
63 | ##### How download from source
64 |
65 | ###### Linux
66 |
67 | ```bash
68 | #copy of the repository
69 | git clone https://github.com/aniko33/DSM-TUI.git
70 | #open folder
71 | cd DSM-TUI
72 | #install req...
73 | pip install -r req.txt
74 | #creating the startup file on /bin
75 | chmod +x dsm && sudo mv dsm /bin
76 | echo remove DSM-TUI folder...
77 | cd ..
78 | rm -rf DSM-TUI
79 | echo now you can start DSM with the command: dsm
80 | ```
81 |
82 | ###### Windows
83 |
84 | ```batch
85 | curl https://raw.githubusercontent.com/aniko33/DSM-TUI/main/dsm-windows.py --output dsm.py
86 | curl https://raw.githubusercontent.com/aniko33/DSM-TUI/main/req.txt --output req.txt
87 | pip install -r req.txt
88 | echo now you can start DSM with the command: python dsm.py
89 | ```
90 |
91 | ### From portable file
92 |
93 | **Downloading from a compiled** file ***could be useful in case the libraries are of poor quality*** or ***just because python no longer allows use***.
94 | The compiled file was compiled with **Pyinstaller**.
95 |
96 | ##### How download from portable file (only Linux)
97 | ```bash
98 | wget https://github.com/aniko33/DSM-TUI/releases/download/v1.1/dsmcom
99 | chmod +x dsmcom
100 | sudo mv dsmcom /bin/dsm
101 | echo now you can start DSM with the command: dsm
102 | ```
103 |
104 | ## Usage
105 |
106 | Using this tool is very easy just ***run the command***: **on *Linux*** `dsm` **on *Windows***: `python dsm.py`
107 | and an ***interface with various functions*** will be given.
108 |
109 | ## Notes
110 |
111 | ### For users
112 |
113 | This app ***needs to be connected to an internet network*** and must be able to ***connect to google.com or, in case, change the link***.
114 |
115 | ### For developers
116 |
117 | there is ***no guide on reading the code and using it***, perhaps in the ***next versions there will be a documentation for developers***
118 |
119 | # Screenshot
120 |
121 | 
122 | 
123 |
124 | ## Contributors
125 |
126 |
129 |
130 | #### Sibriex (Discord > Sibriex#7984)
131 | #### Ares Amigos (Discord > Ares Amigos#2932)
132 |
--------------------------------------------------------------------------------
/dsm:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | import cpuinfo
3 | import shutil
4 | from rich import box
5 | import subprocess
6 | from rich.pretty import Pretty
7 | import time
8 | from rich import print
9 | import sys
10 | from textual.views import DockView
11 | import psutil
12 | from rich.live import Live
13 | from textual.app import App
14 | from textual.widget import Widget
15 | from textual.widgets import Placeholder,ScrollView
16 | from rich.panel import Panel
17 | from rich.text import Text
18 | from rich.console import Console
19 | import requests
20 | import json
21 | from rich.progress import Progress
22 | import platform
23 | console=Console()
24 |
25 | class pie(Widget):
26 | def render(self) -> Panel:
27 | return Panel("(q) [cyan]Exit")
28 |
29 | class title(Widget):
30 | def render(self) -> Panel:
31 | return Panel(Text("Decks-Server-Manager",style="green",justify="center"),box=box.MINIMAL)
32 |
33 | class network(Widget):
34 | def render(self) -> Panel:
35 | #Request for get IP public
36 | ip=requests.get("http://ifconfig.me")
37 | #Request for getting IP info
38 | geo=requests.get("http://ip-api.com/json/?fields=61439")
39 | #Load json
40 | geo=json.loads(geo.text)
41 | #Get uptime PC
42 | uptime=subprocess.getoutput("uptime -p")
43 | #Get info from distro Linux
44 | info=platform.freedesktop_os_release()
45 | #Linux Like (distro)
46 | distro=info["ID"]
47 | #Init cpuinfo
48 | cpu=cpuinfo.get_cpu_info()
49 | #Shell command for getting users on your PC
50 | users=subprocess.getoutput("cut -d: -f1 /etc/passwd")
51 | #Brand exaple > Intel, AMD
52 | cpu_brand=cpu["brand_raw"]
53 | #Get IP info using ip-api.com
54 | geoip=geo["country"]
55 | codeip=geo["countryCode"]
56 | isp=geo["isp"]
57 | return Panel(f"""[yellow]Public IP[/yellow] > [cyan]{ip.text}[/cyan]\n[yellow]Location[/yellow] > [cyan]{geoip}[/cyan] ([purple]{codeip}[/purple])
58 | [yellow]ISP[/yellow] > [cyan]{isp}[/cyan]
59 | [yellow]OS[/yellow] > [cyan]{platform.system()}[/cyan]
60 | [yellow]Distro > [/yellow][cyan]{distro}[/cyan]
61 | [yellow]CPU[/yellow] > [cyan]{cpu_brand}[/cyan]
62 | [yellow]---Users---[/yellow]\n[cyan]{users}[/cyan]
63 | """,title="Network & Info")
64 | class console(Widget):
65 | def on_mount(self):
66 | self.set_interval(1,self.refresh)
67 | def render(self) -> Panel:
68 | process=subprocess.getoutput("ps -ef")
69 | return Panel(process,box=box.MINIMAL,title="Process manager")
70 | class service(Widget):
71 | def on_mount(self):
72 | self.set_interval(1,self.refresh)
73 | def render(self) -> Panel:
74 | service=subprocess.getoutput("systemctl list-units --type=service --state=active")
75 | return Panel(service,title="Service")
76 | class memory(Widget):
77 | def on_mount(self):
78 | self.set_interval(3,self.refresh)
79 | def render(self) -> Panel:
80 | """
81 | Trasfrom byte > K,M,G,T,P
82 | """
83 | def get_size(bytes, suffix="B"):
84 | factor = 1024
85 | for unit in ["", "K", "M", "G", "T", "P"]:
86 | if bytes < factor:
87 | return f"{bytes:.2f}{unit}{suffix}"
88 | bytes /= factor
89 | hdd = shutil.disk_usage('/')
90 |
91 | tz= hdd.total // (2**30)
92 | uz=hdd.used//(2**30)
93 | fz=hdd.free//(2**30)
94 | quotient = uz / tz
95 | used = quotient * 100
96 | quotient = fz / tz
97 | free = quotient * 100
98 | used=int(used)
99 | free=int(free)
100 |
101 | #Printing
102 | if used < 30:
103 | storage=(f"[cyan]Used[/cyan] > [green]({uz} GB) {used}%[/green]\n[cyan]Free[/cyan] > [green]({fz} GB) {free}%[/green]")
104 | elif used > 30:
105 | storage=(f"[cyan]Used[/cyan] > [yellow]({uz} GB) {used}%[/yellow]\n[cyan]Free[/cyan] > [yelllow]({fz} GB) {free}[/yellow]%")
106 | elif used > 60:
107 | storage=(f"[cyan]Used[/cyan] > [red]({uz} GB) {used}%[/red]\n[cyan]Free[/cyan] > [red]({fz}) {free}[/red]")
108 | #init varible
109 | cpufreq = psutil.cpu_freq()
110 | partitions = psutil.disk_partitions()
111 | net_io = psutil.net_io_counters()
112 | for x in partitions:
113 | fstype=x.fstype
114 | uptime=subprocess.getoutput("uptime -p")
115 | svmem = psutil.virtual_memory()
116 | swap = psutil.swap_memory()
117 | return Panel(f"""
118 | [red]---Disk info---[/red]
119 | {storage}
120 | [cyan]File System[/cyan] > [magenta]{fstype}[/magenta]
121 | [red]---CPU Info---[/red]
122 | [cyan]Physical cores[/cyan] > [magenta]{psutil.cpu_count(logical=False)}[/magenta]
123 | [cyan]Cores[/cyan] > [magenta]{psutil.cpu_count(logical=True)}[/magenta]
124 | [red]---CPU freq---[/red]
125 | [cyan]Max freq[/cyan] > [magenta]{cpufreq.max:.2f}Mhz[/magenta]
126 | [cyan]Min freq[/cyan] > [magenta]{cpufreq.min:.2f}Mhz[/magenta]
127 | [cyan]Current freq[/cyan] > [magenta]{cpufreq.current:.2f}[/magenta]
128 | [red]---CPU Usage---[/red]
129 | [cyan]All CPU usage[/cyan] > [magenta]{psutil.cpu_percent()}%[/magenta]
130 | [red]---Memory Monitor---[/red]
131 | [cyan]Total[/cyan] > [magenta]{get_size(svmem.total)}[/magenta]
132 | [cyan]Used[/cyan] > [magenta]{get_size(svmem.used)}[/magenta]
133 | [cyan]Percentage[/cyan] > [magenta]{svmem.percent}%[/magenta]
134 | [red]---Network Monitor---[/red]
135 | [cyan]Total Bytes Sent[/cyan] > [magenta]{get_size(net_io.bytes_sent)}[/magenta]
136 | [cyan]Total Bytes Received[/cyan] > [magenta]{get_size(net_io.bytes_recv)}[/magenta]
137 | [red]---Swap---[/red]
138 | [cyan]Total[/cyan] > [magenta]{get_size(swap.total)}[/magenta]
139 | [cyan]Free[/cyan] > [magenta]{get_size(swap.free)}[/magenta]
140 | [cyan]Used[/cyan] > [magenta]{get_size(swap.used)}[/magenta]
141 | [cyan]Percentage[/cyan] > [magenta]{swap.percent}%[/magenta]
142 | [red]---General Info---[/red]
143 | [cyan]Uptime[/cyan] > [magenta]{uptime}[/magenta]""",title='Server status')
144 | class Ux(App):
145 | async def on_load(self,event):
146 | #keymap
147 | await self.bind("q","quit")
148 | async def on_mount(self) -> None:
149 | #window location
150 | await self.view.dock(title(), edge="top", size=3)
151 | await self.view.dock(pie(), edge="bottom", size=3)
152 | #add scrolling
153 | scroll_view1=ScrollView(contents=memory(),auto_width=True)
154 | scroll_view2=ScrollView(contents=network(),auto_width=True,gutter=(1,1))
155 | await self.view.dock(scroll_view2, edge="right", size=30)
156 | await self.view.dock(scroll_view1,edge="left",size=40)
157 | scroll_view = ScrollView(contents=service(), auto_width=True)
158 | await self.view.dock(scroll_view,edge="top")
159 | #Pinging google.com for verify internet location
160 | url = "http://google.com"
161 | timeout = 5
162 | try:
163 | request = requests.get(url,timeout=timeout)
164 | Ux.run()
165 | except (requests.ConnectionError, requests.Timeout):
166 | print("[red][b]No internet connection.")
167 |
--------------------------------------------------------------------------------
/dsm-windows.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | import cpuinfo
3 | import shutil
4 | from rich import box
5 | import subprocess
6 | import ctypes
7 | from rich.pretty import Pretty
8 | import time
9 | from rich import print
10 | import sys
11 | from textual.views import DockView
12 | import psutil
13 | from rich.live import Live
14 | from textual.app import App
15 | from textual.widget import Widget
16 | from textual.widgets import Placeholder,ScrollView
17 | from rich.panel import Panel
18 | from rich.text import Text
19 | from rich.console import Console
20 | import requests
21 | import json
22 | from rich.progress import Progress
23 | import platform
24 | console=Console()
25 |
26 | class pie(Widget):
27 | def render(self) -> Panel:
28 | return Panel("(q) [cyan]Exit")
29 |
30 | class title(Widget):
31 | def render(self) -> Panel:
32 | return Panel(Text("Decks-Server-Manager",style="green",justify="center"),box=box.MINIMAL)
33 |
34 | class network(Widget):
35 | def render(self) -> Panel:
36 | ip=requests.get("http://ifconfig.me")
37 | geo=requests.get("http://ip-api.com/json/?fields=61439")
38 | geo=json.loads(geo.text)
39 | cpu=cpuinfo.get_cpu_info()
40 | users=subprocess.getoutput("net users")
41 | cpu_brand=cpu["brand_raw"]
42 | geoip=geo["country"]
43 | codeip=geo["countryCode"]
44 | isp=geo['isp']
45 | return Panel(f"""[yellow]Public IP[/yellow] > [cyan]{ip.text}[/cyan]\n[yellow]Location[/yellow] > [cyan]{geoip}[/cyan] ([purple]{codeip}[/purple])"
46 | [yellow]ISP[/yellow] > [cyan]{isp}[/cyan]
47 | [yellow]OS[/yellow] > [cyan]{platform.system()}[/cyan]
48 | [yellow]CPU[/yellow] > [cyan]{cpu_brand}[/cyan]
49 | [yellow]---Users---[/yellow]
50 | [cyan]{users}[/cyan]""",title="Network & Info")
51 | class console(Widget):
52 | def on_mount(self):
53 | self.set_interval(1,self.refresh)
54 | def render(self) -> Panel:
55 | process=subprocess.getoutput("ps -ef")
56 | return Panel(process,box=box.MINIMAL,title="Process manager")
57 | class service(Widget):
58 | def on_mount(self):
59 | self.set_interval(1,self.refresh)
60 | def render(self) -> Panel:
61 | service=subprocess.getoutput("net start")
62 | return Panel(service,title="Service")
63 | class memory(Widget):
64 | def on_mount(self):
65 | self.set_interval(3,self.refresh)
66 | def render(self) -> Panel:
67 | def get_size(bytes, suffix="B"):
68 | factor = 1024
69 | for unit in ["", "K", "M", "G", "T", "P"]:
70 | if bytes < factor:
71 | return f"{bytes:.2f}{unit}{suffix}"
72 | bytes /= factor
73 | hdd = shutil.disk_usage('/')
74 |
75 | tz= hdd.total // (2**30)
76 | uz=hdd.used//(2**30)
77 | fz=hdd.free//(2**30)
78 | quotient = uz / tz
79 | used = quotient * 100
80 | quotient = fz / tz
81 | free = quotient * 100
82 | used=int(used)
83 | free=int(free)
84 |
85 | if used < 30:
86 | storage=(f"[cyan]Used[/cyan] > [green]({uz} GB) {used}%[/green]\n[cyan]Free[/cyan] > [green]({fz} GB) {free}%[/green]")
87 | elif used > 30:
88 | storage=(f"[cyan]Used[/cyan] > [yellow]({uz} GB) {used}%[/yellow]\n[cyan]Free[/cyan] > [yelllow]({fz} GB) {free}[/yellow]%")
89 | elif used > 60:
90 | storage=(f"[cyan]Used[/cyan] > [red]({uz} GB) {used}%[/red]\n[cyan]Free[/cyan] > [red]({fz}) {free}[/red]")
91 | cpufreq = psutil.cpu_freq()
92 | partitions = psutil.disk_partitions()
93 | net_io = psutil.net_io_counters()
94 | for x in partitions:
95 | fstype=x.fstype
96 | lib = ctypes.windll.kernel32
97 | t = lib.GetTickCount64()
98 | t = int(str(t)[:-3])
99 |
100 | mins, sec = divmod(t, 60)
101 | hour, mins = divmod(mins, 60)
102 | days, hour = divmod(hour, 24)
103 |
104 | uptime=(f"{days} days, {hour:02}:{mins:02}:{sec:02}")
105 | svmem = psutil.virtual_memory()
106 | swap = psutil.swap_memory()
107 | return Panel(f"""
108 | [red]---Disk info---[/red]
109 | {storage}
110 | [cyan]File System[/cyan] > [magenta]{fstype}[/magenta]
111 | [red]---CPU Info---[/red]
112 | [cyan]Physical cores[/cyan] > [magenta]{psutil.cpu_count(logical=False)}[/magenta]
113 | [cyan]Cores[/cyan] > [magenta]{psutil.cpu_count(logical=True)}[/magenta]
114 | [red]---CPU freq---[/red]
115 | [cyan]Max freq[/cyan] > [magenta]{cpufreq.max:.2f}Mhz[/magenta]
116 | [cyan]Min freq[/cyan] > [magenta]{cpufreq.min:.2f}Mhz[/magenta]
117 | [cyan]Current freq[/cyan] > [magenta]{cpufreq.current:.2f}[/magenta]
118 | [red]---CPU Usage---[/red]
119 | [cyan]All CPU usage[/cyan] > [magenta]{psutil.cpu_percent()}%[/magenta]
120 | [red]---Memory Monitor---[/red]
121 | [cyan]Total[/cyan] > [magenta]{get_size(svmem.total)}[/magenta]
122 | [cyan]Used[/cyan] > [magenta]{get_size(svmem.used)}[/magenta]
123 | [cyan]Percentage[/cyan] > [magenta]{svmem.percent}%[/magenta]
124 | [red]---Network Monitor---[/red]
125 | [cyan]Total Bytes Sent[/cyan] > [magenta]{get_size(net_io.bytes_sent)}[/magenta]
126 | [cyan]Total Bytes Received[/cyan] > [magenta]{get_size(net_io.bytes_recv)}[/magenta]
127 | [red]---Swap---[/red]
128 | [cyan]Total[/cyan] > [magenta]{get_size(swap.total)}[/magenta]
129 | [cyan]Free[/cyan] > [magenta]{get_size(swap.free)}[/magenta]
130 | [cyan]Used[/cyan] > [magenta]{get_size(swap.used)}[/magenta]
131 | [cyan]Percentage[/cyan] > [magenta]{swap.percent}%[/magenta]
132 | [red]---General Info---[/red]
133 | [cyan]Uptime[/cyan] > [magenta]{uptime}[/magenta]""",title='Server status')
134 | class Ux(App):
135 | async def on_load(self,event):
136 | await self.bind("q","quit")
137 | async def on_mount(self) -> None:
138 | await self.view.dock(title(), edge="top", size=3)
139 | await self.view.dock(pie(), edge="bottom", size=3)
140 | scroll_view1=ScrollView(contents=memory(),auto_width=True)
141 | scroll_view2=ScrollView(contents=network(),auto_width=True,gutter=(1,1))
142 | #ho tolto scroll_view
143 | await self.view.dock(memory(), edge="right", size=30)
144 | await self.view.dock(network(),edge="left",size=40)
145 | scroll_view = ScrollView(contents=service(), auto_width=True)
146 | await self.view.dock(scroll_view,edge="top")
147 | url = "http://google.com"
148 | timeout = 5
149 | try:
150 | request = requests.get(url,timeout=timeout)
151 | Ux.run()
152 | except (requests.ConnectionError, requests.Timeout):
153 | print("[red][b]No internet connection.")
154 |
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | import cpuinfo
3 | import shutil
4 | from rich import box
5 | import subprocess
6 | from rich.pretty import Pretty
7 | import time
8 | from rich import print
9 | import sys
10 | from textual.views import DockView
11 | import psutil
12 | from rich.live import Live
13 | from textual.app import App
14 | from textual.widget import Widget
15 | from textual.widgets import Placeholder,ScrollView
16 | from rich.panel import Panel
17 | from rich.text import Text
18 | from rich.console import Console
19 | import requests
20 | import json
21 | from rich.progress import Progress
22 | import platform
23 | console=Console()
24 |
25 | class pie(Widget):
26 | def render(self) -> Panel:
27 | return Panel("(q) [cyan]Exit")
28 |
29 | class title(Widget):
30 | def render(self) -> Panel:
31 | return Panel(Text("Decks-Server-Manager",style="green",justify="center"),box=box.MINIMAL)
32 |
33 | class network(Widget):
34 | def render(self) -> Panel:
35 | #Request for get IP public
36 | ip=requests.get("http://ifconfig.me")
37 | #Request for getting IP info
38 | geo=requests.get("http://ip-api.com/json/?fields=61439")
39 | #Load json
40 | geo=json.loads(geo.text)
41 | #Get uptime PC
42 | uptime=subprocess.getoutput("uptime -p")
43 | #Get info from distro Linux
44 | info=platform.freedesktop_os_release()
45 | #Linux Like (distro)
46 | distro=info["ID"]
47 | #Init cpuinfo
48 | cpu=cpuinfo.get_cpu_info()
49 | #Shell command for getting users on your PC
50 | users=subprocess.getoutput("cut -d: -f1 /etc/passwd")
51 | #Brand exaple > Intel, AMD
52 | cpu_brand=cpu["brand_raw"]
53 | #Get IP info using ip-api.com
54 | geoip=geo["country"]
55 | codeip=geo["countryCode"]
56 | isp=geo["isp"]
57 | return Panel(f"""[yellow]Public IP[/yellow] > [cyan]{ip.text}[/cyan]\n[yellow]Location[/yellow] > [cyan]{geoip}[/cyan] ([purple]{codeip}[/purple])
58 | [yellow]ISP[/yellow] > [cyan]{isp}[/cyan]
59 | [yellow]OS[/yellow] > [cyan]{platform.system()}[/cyan]
60 | [yellow]Distro > [/yellow][cyan]{distro}[/cyan]
61 | [yellow]CPU[/yellow] > [cyan]{cpu_brand}[/cyan]
62 | [yellow]---Users---[/yellow]\n[cyan]{users}[/cyan]
63 | """,title="Network & Info")
64 | class console(Widget):
65 | def on_mount(self):
66 | self.set_interval(1,self.refresh)
67 | def render(self) -> Panel:
68 | process=subprocess.getoutput("ps -ef")
69 | return Panel(process,box=box.MINIMAL,title="Process manager")
70 | class service(Widget):
71 | def on_mount(self):
72 | self.set_interval(1,self.refresh)
73 | def render(self) -> Panel:
74 | service=subprocess.getoutput("systemctl list-units --type=service --state=active")
75 | return Panel(service,title="Service")
76 | class memory(Widget):
77 | def on_mount(self):
78 | self.set_interval(3,self.refresh)
79 | def render(self) -> Panel:
80 | """
81 | Trasfrom byte > K,M,G,T,P
82 | """
83 | def get_size(bytes, suffix="B"):
84 | factor = 1024
85 | for unit in ["", "K", "M", "G", "T", "P"]:
86 | if bytes < factor:
87 | return f"{bytes:.2f}{unit}{suffix}"
88 | bytes /= factor
89 | hdd = shutil.disk_usage('/')
90 |
91 | tz= hdd.total // (2**30)
92 | uz=hdd.used//(2**30)
93 | fz=hdd.free//(2**30)
94 | quotient = uz / tz
95 | used = quotient * 100
96 | quotient = fz / tz
97 | free = quotient * 100
98 | used=int(used)
99 | free=int(free)
100 |
101 | #Printing
102 | if used < 30:
103 | storage=(f"[cyan]Used[/cyan] > [green]({uz} GB) {used}%[/green]\n[cyan]Free[/cyan] > [green]({fz} GB) {free}%[/green]")
104 | elif used > 30:
105 | storage=(f"[cyan]Used[/cyan] > [yellow]({uz} GB) {used}%[/yellow]\n[cyan]Free[/cyan] > [yelllow]({fz} GB) {free}[/yellow]%")
106 | elif used > 60:
107 | storage=(f"[cyan]Used[/cyan] > [red]({uz} GB) {used}%[/red]\n[cyan]Free[/cyan] > [red]({fz}) {free}[/red]")
108 | #init varible
109 | cpufreq = psutil.cpu_freq()
110 | partitions = psutil.disk_partitions()
111 | net_io = psutil.net_io_counters()
112 | for x in partitions:
113 | fstype=x.fstype
114 | uptime=subprocess.getoutput("uptime -p")
115 | svmem = psutil.virtual_memory()
116 | swap = psutil.swap_memory()
117 | return Panel(f"""
118 | [red]---Disk info---[/red]
119 | {storage}
120 | [cyan]File System[/cyan] > [magenta]{fstype}[/magenta]
121 | [red]---CPU Info---[/red]
122 | [cyan]Physical cores[/cyan] > [magenta]{psutil.cpu_count(logical=False)}[/magenta]
123 | [cyan]Cores[/cyan] > [magenta]{psutil.cpu_count(logical=True)}[/magenta]
124 | [red]---CPU freq---[/red]
125 | [cyan]Max freq[/cyan] > [magenta]{cpufreq.max:.2f}Mhz[/magenta]
126 | [cyan]Min freq[/cyan] > [magenta]{cpufreq.min:.2f}Mhz[/magenta]
127 | [cyan]Current freq[/cyan] > [magenta]{cpufreq.current:.2f}[/magenta]
128 | [red]---CPU Usage---[/red]
129 | [cyan]All CPU usage[/cyan] > [magenta]{psutil.cpu_percent()}%[/magenta]
130 | [red]---Memory Monitor---[/red]
131 | [cyan]Total[/cyan] > [magenta]{get_size(svmem.total)}[/magenta]
132 | [cyan]Used[/cyan] > [magenta]{get_size(svmem.used)}[/magenta]
133 | [cyan]Percentage[/cyan] > [magenta]{svmem.percent}%[/magenta]
134 | [red]---Network Monitor---[/red]
135 | [cyan]Total Bytes Sent[/cyan] > [magenta]{get_size(net_io.bytes_sent)}[/magenta]
136 | [cyan]Total Bytes Received[/cyan] > [magenta]{get_size(net_io.bytes_recv)}[/magenta]
137 | [red]---Swap---[/red]
138 | [cyan]Total[/cyan] > [magenta]{get_size(swap.total)}[/magenta]
139 | [cyan]Free[/cyan] > [magenta]{get_size(swap.free)}[/magenta]
140 | [cyan]Used[/cyan] > [magenta]{get_size(swap.used)}[/magenta]
141 | [cyan]Percentage[/cyan] > [magenta]{swap.percent}%[/magenta]
142 | [red]---General Info---[/red]
143 | [cyan]Uptime[/cyan] > [magenta]{uptime}[/magenta]""",title='Server status')
144 | class Ux(App):
145 | async def on_load(self,event):
146 | #keymap
147 | await self.bind("q","quit")
148 | async def on_mount(self) -> None:
149 | #window location
150 | await self.view.dock(title(), edge="top", size=3)
151 | await self.view.dock(pie(), edge="bottom", size=3)
152 | #add scrolling
153 | scroll_view1=ScrollView(contents=memory(),auto_width=True)
154 | scroll_view2=ScrollView(contents=network(),auto_width=True,gutter=(1,1))
155 | await self.view.dock(scroll_view2, edge="right", size=30)
156 | await self.view.dock(scroll_view1,edge="left",size=40)
157 | scroll_view = ScrollView(contents=service(), auto_width=True)
158 | await self.view.dock(scroll_view,edge="top")
159 | #Pinging google.com for verify internet location
160 | url = "http://google.com"
161 | timeout = 5
162 | try:
163 | request = requests.get(url,timeout=timeout)
164 | Ux.run()
165 | except (requests.ConnectionError, requests.Timeout):
166 | print("[red][b]No internet connection.")
167 |
--------------------------------------------------------------------------------
/req.txt:
--------------------------------------------------------------------------------
1 | py-cpuinfo
2 | rich
3 | textual
4 | psutil
5 | requests
6 |
--------------------------------------------------------------------------------