Skip to content

Commit cb7fc86

Browse files
committed
Refactor and reorganize Python System Monitor codebase
Modularized the codebase into clearly defined components for improved scalability and maintainability. Introduced async scheduling in `main.py` for smoother monitoring updates and added an enhanced UI handler for layout and content management.
1 parent fb903b8 commit cb7fc86

33 files changed

+1790
-346
lines changed

.gitingore

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# UV
98+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
#uv.lock
102+
103+
# poetry
104+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105+
# This is especially recommended for binary packages to ensure reproducibility, and is more
106+
# commonly ignored for libraries.
107+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108+
#poetry.lock
109+
110+
# pdm
111+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112+
#pdm.lock
113+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114+
# in version control.
115+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116+
.pdm.toml
117+
.pdm-python
118+
.pdm-build/
119+
120+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121+
__pypackages__/
122+
123+
# Celery stuff
124+
celerybeat-schedule
125+
celerybeat.pid
126+
127+
# SageMath parsed files
128+
*.sage.py
129+
130+
# Environments
131+
.env
132+
.venv
133+
env/
134+
venv/
135+
ENV/
136+
env.bak/
137+
venv.bak/
138+
139+
# Spyder project settings
140+
.spyderproject
141+
.spyproject
142+
143+
# Rope project settings
144+
.ropeproject
145+
146+
# mkdocs documentation
147+
/site
148+
149+
# mypy
150+
.mypy_cache/
151+
.dmypy.json
152+
dmypy.json
153+
154+
# Pyre type checker
155+
.pyre/
156+
157+
# pytype static type analyzer
158+
.pytype/
159+
160+
# Cython debug symbols
161+
cython_debug/
162+
163+
# PyCharm
164+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166+
# and can be added to the global gitignore or merged into this file. For a more nuclear
167+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
168+
#.idea/
169+
170+
# Ruff stuff:
171+
.ruff_cache/
172+
173+
# PyPI configuration file
174+
.pypirc

README.md

Lines changed: 92 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,113 @@
1-
2-
---
3-
41
# Python System Monitor
52

6-
A terminal-based system monitor application built with Python and the `curses` library. This application provides real-time monitoring of CPU usage, memory usage, network bandwidth, system information, and running processes.
3+
A high-performance, real-time system monitoring tool with an interactive terminal user interface. Monitor CPU, memory, network, processes, and system information with smooth updates and responsive controls.
4+
5+
![Python System Monitor Demo](gif/demo.gif)
76

87
## Features
98

10-
- **CPU Usage**: Displays overall CPU usage as well as usage per core.
11-
- **Memory Usage**: Displays current memory and swap usage.
12-
- **Network Usage**: Shows network bandwidth usage.
13-
- **System Information**: Provides details about the operating system, Python version, hostname, IP address, CPU cores, RAM, and system uptime.
14-
- **Running Processes**: Lists top running processes by memory usage with the ability to highlight and kill processes using the keyboard and mouse.
9+
- 🚀 Real-time system metrics monitoring
10+
- 💻 Per-core CPU usage and temperature tracking
11+
- 🧮 Memory and swap usage visualization
12+
- 🌐 Network bandwidth monitoring with rate smoothing
13+
- 📊 Process management with detailed statistics
14+
- ⚡ Asynchronous architecture for optimal performance
15+
- 🎯 Interactive process control (kill, sort)
16+
- 📱 Responsive terminal UI with automatic resizing
1517

16-
## Prerequisites
18+
## Requirements
1719

18-
- Python 3.6 or higher
19-
- `psutil` library
20+
- Python 3.12+
21+
- Linux/Unix-based system
22+
23+
Required packages:
24+
- psutil>=5.9.0
25+
- aiofiles>=24.1.0
2026

2127
## Installation
2228

2329
1. Clone the repository:
24-
```sh
25-
git clone https://github.com/Hillary520/python_system_monitor.git
26-
cd python_system_monitor
27-
```
30+
```bash
31+
git clone https://github.com/Hillary520/python_system_monitor.git
32+
cd python_system_monitor
33+
```
34+
35+
2. Create a virtual environment (optional but recommended):
36+
```bash
37+
python -m venv venv
38+
source venv/bin/activate # On Windows: venv\Scripts\activate
39+
```
2840

29-
2. Install the required Python libraries:
30-
```sh
31-
pip install psutil
32-
```
41+
3. Install dependencies:
42+
```bash
43+
pip install -r requirements.txt
44+
```
3345

3446
## Usage
3547

36-
Run the main script to start the system monitor:
37-
```sh
38-
python3 main.py
48+
Run the monitor:
49+
50+
```bash
51+
python3 run_monitor.py
3952
```
4053

41-
## Modules
54+
### Controls
4255

43-
- `cpu_monitor.py`: Contains the `CPUMonitor` class to get CPU usage information.
44-
- `memory_monitor.py`: Contains the `MemoryMonitor` class to get memory and swap usage.
45-
- `network_monitor.py`: Contains the `NetworkMonitor` class to get network bandwidth usage.
46-
- `system_info.py`: Contains the `SystemInfo` class to get system information.
47-
- `processes.py`: Contains the `ProcessMonitor` class to get a list of running processes.
56+
- ``/``: Navigate process list
57+
- `k`: Kill selected process
58+
- `q`: Quit
59+
- `r`: Refresh display
60+
- `F5`: Force refresh
61+
62+
## Stress Testing
63+
64+
The project includes a stress test script to verify monitoring capabilities:
65+
```bash
66+
chmod +x stress_test.sh
67+
./stress_test.sh
68+
```
4869

49-
## Controls
70+
## Architecture
5071

51-
- **Arrow Keys**: Navigate through the list of processes.
52-
- **Mouse Click**: Click to select/highlight a process.
53-
- **K**: Kill the highlighted process.
72+
- **Async Core**: Built on Python's asyncio for non-blocking operations
73+
- **Modular Design**: Separate monitors for different system aspects
74+
- **Optimized Updates**: Variable refresh rates per component
75+
- **Resource Efficient**: Minimal CPU/Memory footprint
5476

77+
## Project Structure
78+
79+
```
80+
python_system_monitor/
81+
├── src/
82+
│ └── python_system_monitor/
83+
│ ├── monitors/
84+
│ │ ├── cpu_monitor.py
85+
│ │ ├── memory_monitor.py
86+
│ │ ├── network_monitor.py
87+
│ │ ├── process_monitor.py
88+
│ │ └── system_info.py
89+
│ ├── ui/
90+
│ │ └── ui_handler.py
91+
│ └── main.py
92+
├── stress_test.sh
93+
├── run_monitor.py
94+
├── requirements.txt
95+
└── README.md
96+
```
97+
98+
## Development
99+
100+
To run tests:
101+
```bash
102+
pytest tests/ --cov=python_system_monitor
103+
```
104+
105+
## Acknowledgments
106+
107+
- Built with [psutil](https://github.com/giampaolo/psutil)
108+
- Inspired by tools like [htop](https://github.com/htop-dev/htop), [glances](https://github.com/nicolargo/glances) and [bpytop](https://github.com/aristocratos/bpytop)
109+
110+
## About
111+
112+
This project was created to provide a modern, efficient system monitoring solution with a focus on performance and user experience.
113+
```

__init__.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

cpu_monitor.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

gif/demo.gif

2.91 MB
Loading

0 commit comments

Comments
 (0)