A minimal real-time system monitor (Task-Manager-like) implemented in Python with a FastAPI backend and a small browser frontend (Chart.js). It shows CPU, RAM, Disk, Network, Temperatures, Processes and system information (CPU name, cores, threads, RAM installed, GPU name, OS).
This README explains how to run the project on Windows, what each part does, configuration, and common troubleshooting steps specific to issues you may have encountered.
- CPU usage (total + per-core)
- Memory usage (total, used, percent)
- Disk usage and IO rates
- Network interface rates (bytes/sec)
- Temperatures (where supported)
- Processes list (top by CPU)
- System info: CPU name, physical cores, logical threads, RAM installed, OS
- GPU name: NVML if available; on Windows, falls back to
wmicwhen NVML missing - Real-time dashboard using WebSocket and Chart.js
- README.md
- requirements.txt
- .env.example
- scripts/run_dev.sh
- src/
- monitor_backend/
- main.py
- config.py
- aggregator.py
- broadcaster.py
- collector/
- psutil_collector.py
- gpu_collector.py
- api/
- routes.py
- services/
- process_service.py
- monitor_frontend/
- static/
- index.html
- app.js
- styles.css
- static/
- monitor_backend/
The FastAPI app serves the frontend at / and static files under /static.
- pip install -r requirements.txt
- python -m uvicorn monitor_backend.main:app --reload
-
Open PowerShell in the project root.
-
Create & activate the virtual environment (if not already):
- python -m venv .venv
- ..venv\Scripts\Activate.ps1
- If execution policy blocks activation script for the session:
- Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
-
Install dependencies:
- pip install -r requirements.txt
- (Optional) GPU support: pip install pynvml
-
Ensure
.env(optional):- Copy example: Copy-Item .env.example .env
- Edit
.envto setPOLL_INTERVALorADMIN_TOKENas desired.
-
Start the server:
- cd .\src
- python -m uvicorn monitor_backend.main:app --reload --host 127.0.0.1 --port 8000
-
Open the dashboard in your browser:
- Process-kill endpoint requires
X-Admin-Tokenheader equal toADMIN_TOKEN(set in.envor defaults toadmin-token). Example:- PowerShell: Invoke-RestMethod -Uri http://127.0.0.1:8000/api/processes/123/kill -Method Post -Headers @{ "X-Admin-Token" = "admin-token" }
- Some fields depend on platform support:
- Temperatures and some GPU metrics require system drivers and libraries.
- GPU name is retrieved via NVML (pynvml) when available; on Windows it uses
wmicfallback.
- Killing certain processes may require elevated privileges — run PowerShell as Administrator if needed.
-
Uvicorn import/circular import error:
- If you see
ImportError: cannot import name ... from partially initialized module 'monitor_backend.main' (most likely due to a circular import), ensuremain.pycreates collector/aggregator/broadcaster and defines helper functions before importingmonitor_backend.api.routes. The providedmain.pyalready follows this ordering.
- If you see
-
Pydantic BaseSettings import error:
- If you get a pydantic error about
BaseSettingsmoved topydantic-settings, use the providedconfig.pywhich does not require pydantic, or install a compatible pydantic version:- pip install "pydantic<2.0.0" (not recommended long term) or install
pydantic-settingsand adapt config.
- pip install "pydantic<2.0.0" (not recommended long term) or install
- If you get a pydantic error about
-
Static files 404 (page unstyled / JS missing):
- Ensure
index.htmlreferences assets under/static:<link rel="stylesheet" href="/static/styles.css" /><script src="/static/app.js"></script>
- Confirm files are located in
src/monitor_frontend/static/. - The server mounts static at
/static; after changing files restart uvicorn.
- Ensure
-
Files accidentally include "name=" headers:
- If files were pasted from the README or assistant output, the first line may be
name=...(invalid). Remove any leading lines likename=src/...from .py, .js, .html, .css files. - To detect such files:
- PowerShell (run in project root): Get-ChildItem -Recurse -Path .\src | Select-String -Pattern '^name=' | Select-Object Path, LineNumber, Line
- If files were pasted from the README or assistant output, the first line may be
-
“No snapshot yet” or empty charts:
- Wait 1–2 seconds after server startup for the first poll.
- Check backend logs for poller errors. Snapshot endpoint:
-
WebSocket not connecting:
- Browser console (DevTools) will show WS connection errors. Confirm front-end connects to
/api/ws/metrics(the code usesws://<host>/api/ws/metricsorwss://for HTTPS).
- Browser console (DevTools) will show WS connection errors. Confirm front-end connects to
- Run the app from the
srcfolder (cd src) to avoid needing to set PYTHONPATH. - Restart the server when changing Python files. FastAPI
--reloadwatches for file changes but restart is sometimes required after structural changes. - Use a small
POLL_INTERVAL(default 1.0s). Increase to reduce load.
- Do not expose the server publicly without adding authentication, TLS, and network restrictions.
- For production, run behind a reverse proxy (nginx) and use an application server without
--reload. - Consider containerizing with Docker and using secrets for admin tokens.