Download src/api/infrastructure.py from arimatch1/crewhub: direct link, hf CLI and curl.
- Browser
- Download file 1.9 kB
-
https://huggingface.co/spaces/arimatch1/crewhub/resolve/main/src/api/infrastructure.py
- Command line
-
hf download hf://spaces/arimatch1/crewhub/src/api/infrastructure.py
-
curl -L -o infrastructure.py https://huggingface.co/spaces/arimatch1/crewhub/resolve/main/src/api/infrastructure.py
1.9 kB
| # Copyright (c) 2026 CrewHub. All rights reserved. | |
| # Proprietary and confidential. See LICENSE for details. | |
| """Admin infrastructure usage monitoring endpoints.""" | |
| from fastapi import APIRouter, Depends, Query | |
| from sqlalchemy.ext.asyncio import AsyncSession | |
| from src.api.admin import require_admin, require_super_admin | |
| from src.database import get_db | |
| from src.schemas.infrastructure import ( | |
| InfrastructureCurrentResponse, | |
| InfrastructureHistoryResponse, | |
| ) | |
| from src.services.infrastructure_monitor import InfrastructureMonitorService | |
| router = APIRouter(prefix="/admin/infrastructure", tags=["admin-infrastructure"]) | |
| async def get_current_metrics( | |
| admin=Depends(require_admin), | |
| db: AsyncSession = Depends(get_db), | |
| ): | |
| """Get the latest infrastructure usage snapshot for all metrics.""" | |
| service = InfrastructureMonitorService(db) | |
| return await service.get_current() | |
| async def get_metric_history( | |
| metric: str = Query(..., description="Metric key, e.g. db_storage_bytes"), | |
| days: int = Query(30, ge=1, le=365), | |
| admin=Depends(require_admin), | |
| db: AsyncSession = Depends(get_db), | |
| ): | |
| """Get daily snapshots for a single metric over N days.""" | |
| service = InfrastructureMonitorService(db) | |
| return await service.get_history(metric, days) | |
| async def trigger_collection( | |
| admin=Depends(require_super_admin), | |
| db: AsyncSession = Depends(get_db), | |
| ): | |
| """Manually trigger metric collection (super_admin only).""" | |
| service = InfrastructureMonitorService(db) | |
| results = await service.collect_all() | |
| await service.send_daily_report(results) | |
| await service.check_threshold_crossings(results) | |
| return await service.get_current() | |