# Server Monitor (web) — Linux edition Watches Linux machines in detail from a browser: this computer, and remote servers over the system `ssh` client. It keeps their history from seconds to years, analyzes it with plain statistics (no AI) and fixes common problems automatically. A small Node.js server does the monitoring; the page is plain HTML, CSS and JavaScript with hand-drawn charts and gauges. No npm packages, no build step. It is a port of the C++/Qt desktop app "Server Monitor" and uses the same `servers.json` schema and the same binary history files. ## Requirements - Node.js 22 or newer (only built-in modules are used). - A current browser (Chrome, Edge, Firefox or Safari). - For remote servers: the OpenSSH client (`ssh`) on this computer. Nothing is installed on the servers; they need a POSIX `sh` and `/proc`. ## Run ```sh ./run.sh # starts the server and opens the page # or node server.js # then open http://127.0.0.1:8765 ``` `PORT=9000 node server.js` uses another port. Stop it with Ctrl+C. Monitoring, history, alert rules and the autopilot run as long as the server runs, with or without an open page. Up to five browser tabs can show the monitor at the same time: each tab holds one live connection and browsers allow six per site. ## How it connects - **This machine:** no setup. The collector script (`core/collector.sh`) is piped into `sh`. - **SSH:** the same script is piped through `ssh user@host sh -s`. Keys are recommended (`ssh-copy-id user@host`); a password also works and is handed to ssh through `SSH_ASKPASS`. The script prints the raw contents of `/proc` and `/sys` once per interval; all calculations happen in the Node.js server. Control actions (signals, `systemctl`, console commands, autopilot) run as the login user. Tick **sudo -n** for a server to wrap privileged actions in `sudo -n` (needs passwordless sudo). ## Features - **Dashboard:** a live card per server (gauges, sparklines, health grade), totals, recent events, search. - **Server tabs:** Overview, CPU (per core, temperatures, GPUs), Memory, Storage, Network, Processes (signals, priority), Services (start, stop, restart, enable, disable, logs), History, Insights & Autopilot, Alert rules, Console. - **History:** every sample for 6 h, 1-minute averages and peaks for 30 days, hourly for 2 years, daily for 20 years; downtime is stored too. Ranges from 1 h to all time with min / average / 95th percentile / peak and CSV export. - **Analysis (every minute):** disk-full forecast, memory growth, per-process leaks, runaway processes, failed or flapping services, overload, swap thrashing, anomalies against the same weekday and hour, availability, capacity advice, a health score (0–100, grade A–F) and a weekly heatmap. - **Autopilot:** acts on the findings with cooldowns and limits; **dry run** only reports what it would do. - **Alert rules:** "CPU > 90 % for 60 s → warning → restart a service". Events go to the Events page, to `alerts.log` and, if switched on, to browser notifications. ## Where data is stored `~/.config/ServerMonitorWeb` (or `$XDG_CONFIG_HOME/ServerMonitorWeb`), created for your user only (mode 700): - `servers.json` — servers, rules and autopilot settings (file mode 600). Saved SSH passwords are only lightly disguised, not encrypted, so prefer keys. - `history//{raw,minute,hour,day}.bin` — the history. - `alerts.log` — every event, tab-separated; starts over at 5 MB. ## Security model The page can run shell commands on your servers, so the server only talks to this computer: - It listens on `127.0.0.1` only. For access from elsewhere use an SSH tunnel (`ssh -L 8765:127.0.0.1:8765 this-computer`). - Requests whose `Host` header is not `127.0.0.1:` or `localhost:` are refused (DNS rebinding), and so are requests with a foreign `Origin`. - Everything that changes state is a `POST` with `Content-Type: application/json` and the header `X-SM: 1`. No CORS headers are ever sent, so other web pages can neither send such requests nor read any reply. - Stored SSH passwords are never sent to the browser; the page only learns that one exists. - Data from servers is inserted into the page as text only, and a Content-Security-Policy allows scripts from this server alone. There is no login: every local user who can reach the port can use the monitor. Do not run it on a shared computer. ## Code ``` server.js HTTP server, live updates (Server-Sent Events), JSON API core/platform.js everything Linux-specific: shell, frame parser, command tables, texts core/collector.sh collector script that runs on the monitored machine core/metrics.js one parsed sample + parser helpers core/model.js server config, rules core/history.js history store + analyzer core/session.js ssh/local link, per-server session (rules, autopilot), manager public/ the page: index.html, style.css, app.js, shared.js (formatting used by both sides) ``` The Windows edition differs only in `core/platform.js`, its collector script, this README and the launcher.