31 lines
1.0 KiB
Markdown
31 lines
1.0 KiB
Markdown
# 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.
|