ems-core v1.0.0: Standard EMS platform core
Shared backend + frontend for multi-customer EMS deployments. - 12 enterprise modules: quota, cost, charging, maintenance, analysis, etc. - 120+ API endpoints, 37 database tables - Customer config mechanism (CUSTOMER env var + YAML config) - Collectors: Modbus TCP, MQTT, HTTP API, Sungrow iSolarCloud - Frontend: React 19 + Ant Design + ECharts + Three.js - Infrastructure: Redis cache, rate limiting, aggregation engine Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
53
backend/app/api/v1/collectors.py
Normal file
53
backend/app/api/v1/collectors.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""API endpoints for collector management and status."""
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
router = APIRouter(prefix="/collectors", tags=["collectors"])
|
||||
|
||||
|
||||
def _get_manager():
|
||||
"""Get the global CollectorManager instance."""
|
||||
from app.main import collector_manager
|
||||
if collector_manager is None:
|
||||
raise HTTPException(status_code=503, detail="Collector manager not active (simulator mode)")
|
||||
return collector_manager
|
||||
|
||||
|
||||
@router.get("/status")
|
||||
async def get_collectors_status():
|
||||
"""Get status of all active collectors."""
|
||||
manager = _get_manager()
|
||||
return {
|
||||
"running": manager.is_running,
|
||||
"collector_count": manager.collector_count,
|
||||
"collectors": manager.get_all_status(),
|
||||
}
|
||||
|
||||
|
||||
@router.get("/status/{device_id}")
|
||||
async def get_collector_status(device_id: int):
|
||||
"""Get status of a specific collector."""
|
||||
manager = _get_manager()
|
||||
collector = manager.get_collector(device_id)
|
||||
if not collector:
|
||||
raise HTTPException(status_code=404, detail="No collector for this device")
|
||||
return collector.get_status()
|
||||
|
||||
|
||||
@router.post("/{device_id}/restart")
|
||||
async def restart_collector(device_id: int):
|
||||
"""Restart a specific device collector."""
|
||||
manager = _get_manager()
|
||||
success = await manager.restart_collector(device_id)
|
||||
if not success:
|
||||
raise HTTPException(status_code=400, detail="Failed to restart collector")
|
||||
return {"message": f"Collector for device {device_id} restarted"}
|
||||
|
||||
|
||||
@router.post("/{device_id}/stop")
|
||||
async def stop_collector(device_id: int):
|
||||
"""Stop a specific device collector."""
|
||||
manager = _get_manager()
|
||||
success = await manager.stop_collector(device_id)
|
||||
if not success:
|
||||
raise HTTPException(status_code=404, detail="No running collector for this device")
|
||||
return {"message": f"Collector for device {device_id} stopped"}
|
||||
Reference in New Issue
Block a user