| name | power-sentry-core |
| description | Core knowledge about the PowerSentry codebase architecture, components, data flow, and configuration. Use this skill when asked about the codebase structure, how components interact, or general understanding of the project. |
PowerSentry Core Skill
Overview
PowerSentry is a distributed infrastructure power monitoring and cost optimization system. It tracks energy consumption and electricity costs for infrastructure servers, featuring real-time monitoring via WebSocket, cost projections, and a centralized web dashboard.
Architecture
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Control Panel ā
ā āāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāā ā
ā ā WebSocket ā ā HTTP Server ā ā Database ā ā
ā ā Server ā ā (Web UI) ā ā (Central) ā ā
ā ā :8765 ā ā :8080 ā ā ā ā
ā āāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā²
ā WebSocket
ā
āāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāā
ā ā ā
āāāāāāāā¼āāāāāāāāā āāāāāāāā¼āāāāāāāāā āāāāāāāā¼āāāāāāāāāā
ā Worker Agent ā ā Worker Agent ā ā Worker Agent N ā
ā (Target) ā ā (Target) ā ā (Target) ā
ā Daemon + WS ā ā Daemon + WS ā ā Daemon + WS ā
āāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāā āāāāāāāāāāāāāāāāāā
Components
1. Control Panel
- WebSocket Server (
:8765): Receives real-time metrics from worker agents
- HTTP Server (
:8080): Serves web UI and API endpoints
- Central Database (SQLite): Stores all worker data and historical records
- Web UI (Vue 3 + Tailwind + DaisyUI): Real-time dashboard
- Location:
control-panel/server/server.py (Python)
2. Worker Agents
- Daemon (
daemon.py): Collects system metrics every minute (CPU, RAM, power)
- WebSocket Client (
websocket_client.py): Sends real-time data to control panel
- Local Database (
database.py): SQLite backup storage
- CLI (
cli.py): Service management (install, start, stop, stats, project)
- Power Model (
power.py): Power calculation (CPU TDP, RAM, base power)
- Pricing (
pricing.py): French electricity rates (EDF Tarif Bleu, peak/off-peak)
Codebase Structure
proxmox-power-monitor/
āāā deploy.sh # Deploy worker agent to target (direct or via jump)
āāā deploy-control-panel.sh # Deploy control panel to a server
āāā cli.py # Worker CLI: install, start, stop, stats, project, cleanup
āāā daemon.py # Worker daemon: metrics collection loop
āāā websocket_client.py # WebSocket client for worker ā control panel
āāā database.py # SQLite database (local worker storage)
āāā power.py # Power calculation model
āāā pricing.py # French electricity pricing
āāā metrics.py # System metrics collection
āāā .env.example # Configuration template (copy to .env)
āāā src/ # TypeScript version (legacy/alternative)
ā āāā cli.ts
ā āāā daemon.ts
ā āāā database.ts
ā āāā pricing.ts
ā āāā power.ts
ā āāā metrics.ts
āāā control-panel/
ā āāā server/server.py # WebSocket + HTTP server
ā āāā ui/index.html # Web dashboard (Vue 3 + Tailwind + DaisyUI)
āāā README.md
āāā ARCHITECTURE.md
āāā .gitignore
Data Flow
- Registration: Worker connects and registers with control panel via WebSocket
- Metrics Collection: Worker collects CPU, RAM, uptime every 60 seconds
- Real-time Sync: Worker sends metrics via WebSocket to control panel
- Central Storage: Control panel stores in central database; worker keeps local copy
- UI Updates: Web dashboard displays live metrics and historical charts
- Cost Projection: CLI can project costs for any period (days, weeks, months)
Configuration
Worker (.env or env vars)
PROXMOX_HOST=<target-ip> # Target server
JUMP_HOST=<jump-ip> # Optional: bastion host
JUMP_USER=ubuntu # Jump host SSH user
REMOTE_USER=root # Target SSH user
DB_PATH=/var/lib/proxmox-power-monitor/data.db
CONTROL_PANEL_URL=ws://<control-panel>:8765/worker
Control Panel (env vars)
PYTHONUNBUFFERED=1
CLI Usage
python3 cli.py install
python3 cli.py install --control-panel=ws://<control-panel>:8765/worker
python3 cli.py start
python3 cli.py stop
python3 cli.py status
python3 cli.py stats --total
python3 cli.py stats --daily=7
python3 cli.py stats --hourly=24
python3 cli.py stats --recent=60
python3 cli.py project 14
python3 cli.py cleanup --days=90
python3 cli.py uninstall
WebSocket Protocol
Worker ā Control Panel
- register:
{"type":"register","worker_id":"...","hostname":"...","version":"1.0.0","capabilities":["metrics","projection"]}
- metrics:
{"type":"metrics","worker_id":"...","timestamp":...,"data":{...}}
- heartbeat: Every 30 seconds
Control Panel ā Worker
- ack: Acknowledgment of received data
- config: Configuration updates
- reconnect: Reconnection request
Security
- Token-based Authentication: Simple token for WebSocket connections
- TLS Support: Use WSS for production deployments
- Input Validation: All incoming data validated
- Worker Isolation: Each worker can only access its own data
- No secrets in codebase: All IPs/credentials loaded via
.env (gitignored)