# Server Monitor (web) — Windows edition Watches Windows 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 (Edge, Chrome or Firefox). - Windows PowerShell 5.1 or newer on every monitored machine (part of Windows). - For remote servers: the OpenSSH client (`ssh.exe`, part of Windows 10/11 and Server 2019+) on this computer and the **OpenSSH Server** feature on the servers. Nothing else is installed there. ## Run ```bat run.bat rem starts the server and opens the page rem or node server.js rem then open http://127.0.0.1:8765 ``` `set PORT=9000` before starting 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.ps1`) is piped into `powershell`. - **SSH:** the same script is piped through `ssh user@host powershell …`. Keys are recommended (add your public key to the server's `authorized_keys`); a password also works and is handed to ssh through `SSH_ASKPASS`. PowerShell is started with a fixed encoded command that runs whatever script arrives on standard input, so no quoting problems can occur in cmd.exe, PowerShell or ssh. The script prints counters from CIM and .NET once per interval; all calculations happen in the Node.js server. Control actions (ending processes, services, console commands, autopilot) run as the user of the monitor (or the SSH login user). There is no sudo on Windows: start the monitor from an elevated prompt, or log in as an administrator over SSH, when you need privileged actions and the owners of all processes. ## 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 (end task, kill, priority), Services (start, stop, restart, enable, disable, event log), History, Insights & Autopilot, Alert rules, Console (PowerShell). - **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. The load average is computed like the Unix one (busy cores + processor queue, averaged over 1, 5 and 15 minutes). A service counts as failed when it starts automatically, is stopped and ended with an error. ## Where data is stored `%APPDATA%\ServerMonitorWeb`: - `servers.json` — servers, rules and autopilot settings. 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 PowerShell 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 Windows-specific: shell, frame parser, command tables, texts core/collector.ps1 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 Linux edition differs only in `core/platform.js`, its collector script, this README and the launcher.