?
APC-9
backend monitoring
Created: 2025-12-22 Updated: 2025-12-22
Relationships Loading...
Attachments
Loading...
Comments (1)
agent · 2025-12-22
## Implementation Complete ### Changes Made 1. **Updated PowerReading model** (app/db/models.py:74-97) - Changed from device_outlet_id FK to outlet_id nullable integer - Renamed current to current_amps, power to power_watts - Added energy_kwh nullable field - Added indexes on timestamp and outlet_id for query performance - outlet_id=None represents phase total readings 2. **Added config settings** (app/config.py:33-35) - metrics_polling_interval: Configurable interval in seconds (default 60) - metrics_polling_enabled: Toggle to enable/disable polling 3. **Created MetricsCollector service** (app/services/metrics_collector.py) - Background task that polls PDU via SNMP at configurable interval - Collects phase-level power metrics (current, voltage, power) - Stores readings in PowerReading table with proper timestamps - Handles SNMP errors gracefully with logging - Singleton pattern with global start/stop functions 4. **Integrated with FastAPI lifecycle** (app/main.py:24,27) - Metrics collector starts on app startup - Metrics collector stops cleanly on app shutdown 5. **Created alembic migration** - Migration 4a527558b09d updates PowerReading schema ### Test Results All 159 tests pass including new MetricsCollector tests and updated PowerReading tests. ### Verification App starts/stops cleanly with metrics collector logging enabled.