Skip to content

Commit fb903b8

Browse files
committed
fixed bugs
1 parent 744d1d9 commit fb903b8

File tree

7 files changed

+43
-41
lines changed

7 files changed

+43
-41
lines changed

README.md

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,54 @@
1-
# System Monitor
21

3-
This Python script is a simple system monitor that displays CPU, memory, and network bandwidth usage in a terminal. It uses the `psutil` library to retrieve system information.
2+
---
43

5-
## Features
6-
7-
- Displays CPU and memory usage in a visual format using hash (`#`) and hyphen (`-`) characters.
8-
- Monitors network bandwidth usage and shows the received, sent, and total data transfer rates.
9-
- Continuously updates the output every 0.5 seconds.
10-
- Clears the terminal screen before displaying the updated output.
11-
12-
## Requirements
4+
# Python System Monitor
135

14-
- Python 3.x
15-
- `psutil` library (install with `pip install psutil`)
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.
167

17-
## Usage
8+
## Features
189

19-
1. Clone or download the repository.
20-
2. Open a terminal and navigate to the project directory.
21-
3. Run the script with `python system_monitor.py`.
22-
4. The output will be displayed in the terminal, updating every 0.5 seconds.
23-
5. Press `Ctrl+C` to exit the program.
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.
2415

25-
## Todo
16+
## Prerequisites
2617

27-
The following features can be added to enhance the system monitor:
18+
- Python 3.6 or higher
19+
- `psutil` library
2820

29-
### System Information
21+
## Installation
3022

31-
Add functionality to display additional system information such as:
23+
1. Clone the repository:
24+
```sh
25+
git clone https://github.com/Hillary520/python_system_monitor.git
26+
cd python_system_monitor
27+
```
3228

33-
- Operating system name and version
34-
- System uptime
35-
- CPU model and number of cores
36-
- Total and available RAM
29+
2. Install the required Python libraries:
30+
```sh
31+
pip install psutil
32+
```
3733

38-
### Running Processes
34+
## Usage
3935

40-
Implement a feature to display a list of currently running processes on the system, including:
36+
Run the main script to start the system monitor:
37+
```sh
38+
python3 main.py
39+
```
4140

42-
- Process name
43-
- Process ID (PID)
44-
- CPU and memory usage for each process
41+
## Modules
4542

46-
You can use the `psutil.process_iter()` function to iterate over all running processes and retrieve the necessary information.
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.
4748

48-
## Contributing
49+
## Controls
4950

50-
Contributions are welcome! If you find any issues or have ideas for improvements, please open an issue or submit a pull request.
51+
- **Arrow Keys**: Navigate through the list of processes.
52+
- **Mouse Click**: Click to select/highlight a process.
53+
- **K**: Kill the highlighted process.
5154

cpu_monitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ def _format_usage(self, cpu):
2020
def _format_core_usage(self, core_idx, core):
2121
core_percent = core / 100.0
2222
core_visual = '#' * int(core_percent * self.bars) + '-' * (self.bars - int(core_percent * self.bars))
23-
return f"Core {core_idx}: [{core_visual}] {core:.2f}%"
23+
return f"Core {core_idx}: [{core_visual}] {core:.2f}%"

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,4 @@ def print_processes(processes_output, process_start):
124124
print("\nExiting...")
125125

126126
if __name__ == "__main__":
127-
curses.wrapper(main)
127+
curses.wrapper(main)

memory_monitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ def get_swap_usage(self):
2020
def _format_usage_swap(self, swap):
2121
swap_percent = swap / 100.0
2222
swap_visual = '#' * int(swap_percent * self.bars) + '-' * (self.bars - int(swap_percent * self.bars))
23-
return f"Swap: [{swap_visual}] {swap:.2f}%"
23+
return f"Swap: [{swap_visual}] {swap:.2f}%"

network_monitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ def get_bandwidth_usage(self):
1919
sent_kb = new_sent / 1024
2020
total_kb = (new_received + new_sent) / 1024
2121

22-
return f"Received: {received_kb:.2f} KB | Sent: {sent_kb:.2f} KB | Total: {total_kb:.2f} KB"
22+
return f"Received: {received_kb:.2f} KB | Sent: {sent_kb:.2f} KB | Total: {total_kb:.2f} KB"

processes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ def get_running_processes(self, num_processes=10):
99
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
1010
continue
1111
sorted_processes = sorted(processes, key=lambda p: p['memory_percent'], reverse=True)
12-
return sorted_processes[:num_processes]
12+
return sorted_processes[:num_processes]

system_info.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,4 @@ def _parse_health_info(self, health_info, key):
116116
return health_info.split(f"{key} = ")[1].split('\n')[0].strip()
117117

118118
def _parse_battery_report(self, report, key):
119-
return report.split(f'{key}')[1].split('<td>')[1].split(' mWh')[0].replace(',', '')
120-
119+
return report.split(f'{key}')[1].split('<td>')[1].split(' mWh')[0].replace(',', '')

0 commit comments

Comments
 (0)