|
| 1 | +# Deployment Guide |
| 2 | + |
| 3 | +This guide covers deploying ServerMonitor to a server (Raspberry Pi, VPS, or any Linux host) using Docker Compose. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Docker and Docker Compose installed on the target machine |
| 8 | +- Git (to clone the repo) |
| 9 | +- Network access from the target machine to all monitored systems (SSH, Docker API, qBit Web UI, UniFi controller) |
| 10 | + |
| 11 | +## Step 1: Get the Code on Your Server |
| 12 | + |
| 13 | +```bash |
| 14 | +ssh your-server |
| 15 | +mkdir -p ~/container && cd ~/container |
| 16 | +git clone <repo-url> ServerMonitor |
| 17 | +cd ServerMonitor |
| 18 | +``` |
| 19 | + |
| 20 | +Or if you're syncing from a local machine: |
| 21 | + |
| 22 | +```bash |
| 23 | +rsync -avz --exclude node_modules --exclude venv --exclude __pycache__ \ |
| 24 | + ./ your-server:~/container/ServerMonitor/ |
| 25 | +``` |
| 26 | + |
| 27 | +## Step 2: Create Your Configuration |
| 28 | + |
| 29 | +```bash |
| 30 | +cp backend/config.example.yaml backend/config.yaml |
| 31 | +nano backend/config.yaml |
| 32 | +``` |
| 33 | + |
| 34 | +Fill in the actual IPs, usernames, and passwords for your systems. Only enable the collectors you need -- set `enabled: false` on the rest. |
| 35 | + |
| 36 | +**Minimal example** (just one Linux server): |
| 37 | + |
| 38 | +```yaml |
| 39 | +poll_interval: 5 |
| 40 | + |
| 41 | +systems: |
| 42 | + - id: my-server |
| 43 | + name: "My Server" |
| 44 | + type: linux |
| 45 | + enabled: true |
| 46 | + config: |
| 47 | + host: 192.168.1.100 |
| 48 | + port: 22 |
| 49 | + username: monitor |
| 50 | + password: your-password |
| 51 | +``` |
| 52 | +
|
| 53 | +### Collector-Specific Setup |
| 54 | +
|
| 55 | +**Linux servers:** The SSH user needs read access to `/proc/stat`, `/proc/meminfo`, `/proc/net/dev`, and permission to run `df`, `sensors` (optional, for temperatures). |
| 56 | + |
| 57 | +**Docker:** Either mount the local socket (default in docker-compose.yml) or expose the Docker API on a TCP port (`tcp://host:2375`). For remote Docker hosts, make sure the API port is reachable. |
| 58 | + |
| 59 | +**qBittorrent:** Enable the Web UI in qBittorrent settings. Note the port (default 8080) and credentials. |
| 60 | + |
| 61 | +**UniFi:** Generate an API key from your UniFi controller's settings. The controller must be reachable over HTTPS (port 443 by default). Set `verify_ssl: false` if using a self-signed certificate. |
| 62 | + |
| 63 | +**UNAS/NAS:** SSH access with permissions to run `zpool`, `df`, `lsblk`, and `smartctl`. |
| 64 | + |
| 65 | +## Step 3: Deploy with Docker Compose |
| 66 | + |
| 67 | +```bash |
| 68 | +docker compose up --build -d |
| 69 | +``` |
| 70 | + |
| 71 | +This builds both images and starts: |
| 72 | +- **backend** on port 8742 (host networking) |
| 73 | +- **frontend** on port 4829 (Nginx serving the Vue SPA + reverse proxy) |
| 74 | + |
| 75 | +Verify everything is running: |
| 76 | + |
| 77 | +```bash |
| 78 | +docker compose ps |
| 79 | +docker compose logs --tail=30 backend |
| 80 | +docker compose logs --tail=30 frontend |
| 81 | +``` |
| 82 | + |
| 83 | +Open `http://<server-ip>:4829` in your browser. |
| 84 | + |
| 85 | +## Step 4: Verify |
| 86 | + |
| 87 | +1. The dashboard should load at `http://<server-ip>:4829` |
| 88 | +2. Check the connection indicator in the top nav -- it should show "Connected" |
| 89 | +3. System cards should appear within 5-10 seconds as the first collection cycle completes |
| 90 | +4. If a system shows "offline", check that the target is reachable from the server and credentials are correct |
| 91 | + |
| 92 | +Quick API test: |
| 93 | + |
| 94 | +```bash |
| 95 | +curl http://localhost:8742/health |
| 96 | +curl http://localhost:8742/api/systems |
| 97 | +``` |
| 98 | + |
| 99 | +## Updating |
| 100 | + |
| 101 | +Pull the latest code and rebuild: |
| 102 | + |
| 103 | +```bash |
| 104 | +cd ~/container/ServerMonitor |
| 105 | +git pull |
| 106 | +docker compose up --build -d |
| 107 | +``` |
| 108 | + |
| 109 | +To rebuild a single service: |
| 110 | + |
| 111 | +```bash |
| 112 | +docker compose up --build -d backend # just the backend |
| 113 | +docker compose up --build -d frontend # just the frontend |
| 114 | +``` |
| 115 | + |
| 116 | +## Raspberry Pi Notes |
| 117 | + |
| 118 | +ServerMonitor runs well on a Raspberry Pi 4 (2GB+ RAM recommended). A few things to keep in mind: |
| 119 | + |
| 120 | +- **First build is slow** -- npm install and pip install take a while on ARM. Subsequent rebuilds use Docker layer caching and are much faster. |
| 121 | +- **Memory:** With all collectors enabled, expect ~150-200MB total RAM usage for both containers. |
| 122 | +- **Docker socket:** The compose file already mounts `/var/run/docker.sock` so the Docker collector can monitor containers on the Pi itself. |
| 123 | +- **Temperatures:** If the Pi is also one of your monitored Linux servers, `sensors` may not be available. The collector will fall back to reading `/sys/class/thermal/thermal_zone*/temp`. |
| 124 | + |
| 125 | +### Recommended Pi Setup |
| 126 | + |
| 127 | +```bash |
| 128 | +# Install Docker |
| 129 | +curl -fsSL https://get.docker.com | sh |
| 130 | +sudo usermod -aG docker $USER |
| 131 | +# Log out and back in |
| 132 | +
|
| 133 | +# Install Docker Compose plugin |
| 134 | +sudo apt install docker-compose-plugin |
| 135 | +
|
| 136 | +# Clone and deploy |
| 137 | +mkdir -p ~/container && cd ~/container |
| 138 | +git clone <repo-url> ServerMonitor |
| 139 | +cd ServerMonitor |
| 140 | +cp backend/config.example.yaml backend/config.yaml |
| 141 | +nano backend/config.yaml # configure your systems |
| 142 | +docker compose up --build -d |
| 143 | +``` |
| 144 | + |
| 145 | +## Running Without Docker |
| 146 | + |
| 147 | +If you prefer to run directly on the host: |
| 148 | + |
| 149 | +### Backend |
| 150 | + |
| 151 | +```bash |
| 152 | +cd backend |
| 153 | +python3 -m venv venv |
| 154 | +source venv/bin/activate |
| 155 | +pip install -r requirements.txt |
| 156 | +
|
| 157 | +# Set config path (optional, defaults to config.yaml in cwd) |
| 158 | +export SERVERMONITOR_CONFIG_PATH=./config.yaml |
| 159 | +
|
| 160 | +uvicorn app.main:app --host 0.0.0.0 --port 8742 |
| 161 | +``` |
| 162 | + |
| 163 | +### Frontend (Production Build) |
| 164 | + |
| 165 | +```bash |
| 166 | +cd frontend |
| 167 | +npm install |
| 168 | +npm run build |
| 169 | +``` |
| 170 | + |
| 171 | +Serve the `frontend/dist/` directory with any web server. You'll need to configure a reverse proxy for `/api` and `/ws` to point to the backend. |
| 172 | + |
| 173 | +Example Nginx config: |
| 174 | + |
| 175 | +```nginx |
| 176 | +server { |
| 177 | + listen 4829; |
| 178 | + root /path/to/frontend/dist; |
| 179 | + index index.html; |
| 180 | +
|
| 181 | + location / { |
| 182 | + try_files $uri $uri/ /index.html; |
| 183 | + } |
| 184 | +
|
| 185 | + location /api { |
| 186 | + proxy_pass http://127.0.0.1:8742; |
| 187 | + } |
| 188 | +
|
| 189 | + location /ws { |
| 190 | + proxy_pass http://127.0.0.1:8742; |
| 191 | + proxy_http_version 1.1; |
| 192 | + proxy_set_header Upgrade $http_upgrade; |
| 193 | + proxy_set_header Connection "upgrade"; |
| 194 | + proxy_read_timeout 86400; |
| 195 | + } |
| 196 | +} |
| 197 | +``` |
| 198 | + |
| 199 | +## Mock Mode |
| 200 | + |
| 201 | +To run with fake data (useful for development or demos): |
| 202 | + |
| 203 | +```bash |
| 204 | +SERVERMONITOR_MOCK_MODE=true uvicorn app.main:app --host 0.0.0.0 --port 8742 |
| 205 | +``` |
| 206 | + |
| 207 | +Or in Docker Compose, add to the backend environment: |
| 208 | + |
| 209 | +```yaml |
| 210 | +environment: |
| 211 | + - SERVERMONITOR_CONFIG_PATH=/app/config.yaml |
| 212 | + - SERVERMONITOR_MOCK_MODE=true |
| 213 | +``` |
| 214 | + |
| 215 | +## Troubleshooting |
| 216 | + |
| 217 | +### Dashboard loads but no systems appear |
| 218 | + |
| 219 | +- Check backend logs: `docker compose logs backend` |
| 220 | +- Verify config.yaml has at least one system with `enabled: true` |
| 221 | +- Test connectivity from the server to the target system (e.g., `ssh user@host` or `curl http://host:port`) |
| 222 | + |
| 223 | +### WebSocket disconnects / falls back to polling |
| 224 | + |
| 225 | +- The frontend automatically reconnects and falls back to HTTP polling -- this is by design |
| 226 | +- If you're behind a reverse proxy or load balancer, make sure WebSocket upgrade headers are forwarded |
| 227 | +- Check that port 8742 is not blocked by a firewall |
| 228 | + |
| 229 | +### A system shows "offline" |
| 230 | + |
| 231 | +- The collector can't reach the target. Common causes: |
| 232 | + - Wrong IP/port/credentials in config.yaml |
| 233 | + - Firewall blocking the connection |
| 234 | + - Target service not running (e.g., Docker API not exposed, qBit Web UI disabled) |
| 235 | +- Check the error in backend logs for specifics |
| 236 | + |
| 237 | +### Docker collector can't connect |
| 238 | + |
| 239 | +- **Local socket:** Make sure `/var/run/docker.sock` is mounted (it is by default in docker-compose.yml) |
| 240 | +- **Remote TCP:** Docker API must be explicitly exposed on the target host (`dockerd -H tcp://0.0.0.0:2375`). This has no authentication -- only use on trusted networks. |
| 241 | + |
| 242 | +### High CPU on the server |
| 243 | + |
| 244 | +- Increase `poll_interval` in config.yaml (e.g., from 5 to 15 seconds) |
| 245 | +- Disable collectors you don't need |
| 246 | +- Hot-reload config without restart: `curl -X POST http://localhost:8742/api/reload` |
0 commit comments