This commit is contained in:
2025-12-27 01:17:10 +01:00
commit e0fa3018ea
315 changed files with 2167 additions and 0 deletions

30
docs/backend.md Normal file
View File

@@ -0,0 +1,30 @@
# Backend Documentation
The backend is built with **FastAPI**, providing a high-performance API to serve system metrics.
## Core Files
### `main.py`
- Entry point of the application.
- Defines the FastAPI app and CORS middleware.
- **Endpoints**:
- `GET /`: Serves the `monitor.html` file.
- `GET /api/status`: Orchestrates the monitoring tasks and returns a JSON response.
- **Parallel Execution**: Uses `asyncio.gather` and `asyncio.to_thread` to run blocking SSH/HTTP calls concurrently.
### `monitor_logic.py`
- Contains the low-level monitoring functions.
- **`get_ssh_data()`**:
- Connects via SSH using `paramiko`.
- Executes commands to fetch:
- CPU Usage: `top`
- RAM Usage: `free`
- Disk Space: `df`
- Temperature: `/sys/class/thermal/thermal_zone0/temp` or `vcgencmd`.
- **`check_web_service()`**:
- Performs an HTTP GET request.
- Calculates latency in milliseconds.
## Environment Variables
- `PC_PASS`: SSH password for the Ubuntu Server.
- `PI_PASS`: SSH password for the Raspberry Pi.