Related Products
diff --git a/asf-cloud-server/monitor/Nabd.png b/asf-cloud-server/monitor/Nabd.png new file mode 100644 index 0000000..c445709 Binary files /dev/null and b/asf-cloud-server/monitor/Nabd.png differ diff --git a/asf-cloud-server/monitor/QUICKSTART.md b/asf-cloud-server/monitor/QUICKSTART.md new file mode 100644 index 0000000..e4306dd --- /dev/null +++ b/asf-cloud-server/monitor/QUICKSTART.md @@ -0,0 +1,27 @@ +# 🚀 Quickstart Guide + +Welcome to the ASF Infrastructure Monitor! + +## 1. Setup Environment +Create a `.env` file in the root directory: +```env +PC_PASS=your_pc_password +PI_PASS=your_pi_password +``` + +## 2. Deploy +Run the following command: +```bash +docker compose up -d --build +``` + +## 3. Access +The dashboard will be available at: +`http://asf.monitor.nabd-co.com` (after Caddy setup) + +## 4. Documentation +For more details, check the `docs/` folder: +- [Architecture](docs/architecture.md) +- [Backend](docs/backend.md) +- [Frontend](docs/frontend.md) +- [Deployment](docs/deployment.md) diff --git a/asf-cloud-server/monitor/app image.png b/asf-cloud-server/monitor/app image.png new file mode 100644 index 0000000..6e47ea2 Binary files /dev/null and b/asf-cloud-server/monitor/app image.png differ diff --git a/asf-cloud-server/monitor/app logo.png b/asf-cloud-server/monitor/app logo.png new file mode 100644 index 0000000..3e4bd74 Binary files /dev/null and b/asf-cloud-server/monitor/app logo.png differ diff --git a/asf-cloud-server/monitor/docs/architecture.md b/asf-cloud-server/monitor/docs/architecture.md new file mode 100644 index 0000000..d1d6f21 --- /dev/null +++ b/asf-cloud-server/monitor/docs/architecture.md @@ -0,0 +1,41 @@ +# Architecture Overview + +The ASF Infrastructure Monitor is a lightweight, real-time monitoring solution designed to track the health of local servers and web services. + +## System Components + +```mermaid +graph TD + User((User Browser)) + Caddy[Caddy Proxy] + MonitorApp[Monitor App Container] + + subgraph "Local Network / Internet" + PC[Ubuntu Server PC] + PI[Raspberry Pi] + WebServices[Web Services] + end + + User -->|HTTPS| Caddy + Caddy -->|HTTP| MonitorApp + + MonitorApp -->|SSH| PC + MonitorApp -->|SSH| PI + MonitorApp -->|HTTP/Ping| WebServices +``` + +### 1. Frontend (Client-Side) +- **Technology**: HTML5, Vanilla CSS, JavaScript (ES6+). +- **Libraries**: Chart.js for gauges, FontAwesome for icons. +- **Functionality**: Fetches data from the backend every 60 seconds and updates the UI dynamically without page reloads. + +### 2. Backend (Server-Side) +- **Technology**: Python 3.11, FastAPI. +- **Monitoring Logic**: + - **SSH**: Uses `paramiko` to execute remote commands on the PC and Raspberry Pi. + - **Web**: Uses `requests` to check the status and latency of web services. +- **Concurrency**: Uses `asyncio` to perform all monitoring checks in parallel, ensuring fast response times. + +### 3. Deployment +- **Containerization**: Docker & Docker Compose. +- **Proxy**: Caddy handles SSL termination and routes traffic to the container. diff --git a/asf-cloud-server/monitor/docs/backend.md b/asf-cloud-server/monitor/docs/backend.md new file mode 100644 index 0000000..94071f3 --- /dev/null +++ b/asf-cloud-server/monitor/docs/backend.md @@ -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. diff --git a/asf-cloud-server/monitor/docs/deployment.md b/asf-cloud-server/monitor/docs/deployment.md new file mode 100644 index 0000000..3580fa4 --- /dev/null +++ b/asf-cloud-server/monitor/docs/deployment.md @@ -0,0 +1,36 @@ +# Deployment Documentation + +The application is designed to be deployed as a Docker container behind a Caddy reverse proxy. + +## Docker Setup + +### `Dockerfile` +- Based on `python:3.11-slim`. +- Installs `iputils-ping` for network diagnostics. +- Uses `uvicorn` to serve the FastAPI app. + +### `docker-compose.yml` +- Defines the `monitor-app` service. +- Connects to `caddy_network` for external access. +- Passes SSH credentials via environment variables. + +## Caddy Configuration +Add this to your `Caddyfile`: + +```caddy +asf.monitor.nabd-co.com { + reverse_proxy monitor-app:8000 +} +``` + +## Troubleshooting + +### `KeyError: 'ContainerConfig'` +This error occurs when using `docker-compose` V1 with images built by newer Docker versions. +**Solution**: Use `docker compose` (V2) or disable BuildKit: +```bash +DOCKER_BUILDKIT=0 COMPOSE_DOCKER_CLI_BUILD=0 docker-compose up -d --build +``` + +### SSH Connectivity +Ensure the cloud server can reach the target IPs/hostnames on the specified ports (49152 and 2222). diff --git a/asf-cloud-server/monitor/docs/frontend.md b/asf-cloud-server/monitor/docs/frontend.md new file mode 100644 index 0000000..ca2b69d --- /dev/null +++ b/asf-cloud-server/monitor/docs/frontend.md @@ -0,0 +1,19 @@ +# Frontend Documentation + +The frontend is a modern, responsive dashboard designed for high visibility and aesthetic appeal. + +## Design Principles +- **Glassmorphism**: Uses semi-transparent backgrounds with blur effects (`backdrop-filter`). +- **Dark Mode**: Optimized for low-light environments (NOC/Dashboard style). +- **Vibrant Accents**: Uses gradients and neon colors to highlight status and metrics. + +## Key Features +- **Dynamic Gauges**: Built with `Chart.js` to show CPU and RAM usage. +- **Status Badges**: Real-time color-coded badges (Online/Offline). +- **Auto-Refresh**: Polls the `/api/status` endpoint every 1 minute. +- **Loading State**: A smooth loading overlay that disappears once the first data batch is received. + +## UI Components +- **Server Cards**: Detailed metrics for PC and Raspberry Pi. +- **Web Services List**: Compact list of external services with latency tracking. +- **Responsive Grid**: Automatically adjusts layout based on screen size. diff --git a/asf-cloud-server/monitor/main.py b/asf-cloud-server/monitor/main.py index 105f7e8..fdca136 100644 --- a/asf-cloud-server/monitor/main.py +++ b/asf-cloud-server/monitor/main.py @@ -1,5 +1,6 @@ from fastapi import FastAPI from fastapi.responses import FileResponse +from fastapi.staticfiles import StaticFiles from fastapi.middleware.cors import CORSMiddleware import os from dotenv import load_dotenv @@ -17,6 +18,9 @@ app.add_middleware( allow_headers=["*"], ) +# Serve static files from the current directory +app.mount("/static", StaticFiles(directory="."), name="static") + # Configuration from environment variables PC_HOST = "asf-server.duckdns.org" PC_PORT = 49152 diff --git a/asf-cloud-server/monitor/monitor.html b/asf-cloud-server/monitor/monitor.html index 1e661bf..6b1c12f 100644 --- a/asf-cloud-server/monitor/monitor.html +++ b/asf-cloud-server/monitor/monitor.html @@ -5,6 +5,7 @@
+ Real-time system health and service availability
Creating...