ruvnet/RuView · error · HTTPException

Failed to get system metrics: {str(e)}

Error message

Failed to get system metrics: {str(e)}

What it means

Raised as HTTP 500 by GET /metrics (routers/health.py:281) when gathering system metrics throws — either the unauthenticated basic metrics or, when authenticated, get_detailed_metrics executed via asyncio.to_thread. The raw exception text is embedded in the detail; the log line 'Error getting system metrics:' holds the underlying cause.

Source

Thrown at archive/v1/src/api/routers/health.py:281

    current_user: Optional[Dict] = Depends(get_current_user)
):
    """Get detailed system metrics."""
    try:
        metrics = await asyncio.to_thread(get_system_metrics)
        
        # Add additional metrics if authenticated
        if current_user:
            detailed = await asyncio.to_thread(get_detailed_metrics)
            metrics.update(detailed)
        
        return {
            "timestamp": datetime.utcnow().isoformat(),
            "metrics": metrics
        }
        
    except Exception as e:
        logger.error(f"Error getting system metrics: {e}")
        raise HTTPException(
            status_code=500,
            detail=f"Failed to get system metrics: {str(e)}"
        )


@router.get("/version")
async def get_version_info():
    """Get application version information."""
    settings = get_settings()
    
    return {
        "name": settings.app_name,
        "version": settings.version,
        "environment": settings.environment,
        "debug": settings.debug,
        "timestamp": datetime.utcnow().isoformat()
    }

View on GitHub (pinned to 4685618388)

Solutions

  1. Check the server log for 'Error getting system metrics:' to get the real exception
  2. Install/permit the metrics dependency and give the process read access to /proc
  3. Degrade instead of 500: return basic metrics with an 'unavailable' marker when detailed collection fails
  4. Remember the detailed branch only runs when authenticated — most scrapers call unauthenticated

Example fix

# before
detailed = await asyncio.to_thread(get_detailed_metrics)
metrics.update(detailed)

# after
try:
    detailed = await asyncio.to_thread(get_detailed_metrics)
    metrics.update(detailed)
except Exception:
    logger.exception('detailed metrics unavailable')
    metrics['detailed'] = 'unavailable'
Defensive patterns

Strategy: fallback

Validate before calling

try:
    metrics = (await client.get('/metrics', timeout=5)).json()
except Exception:
    metrics = None
if metrics is None:
    logger.warning('metrics unavailable; continuing without them')

Try / catch

try:
    payload = (await client.get('/metrics')).json()
except Exception:
    payload = {'timestamp': None, 'metrics': {}}
# dashboards render unknowns when metrics are missing

Prevention

When it happens

Trigger: The metrics source fails (psutil missing, /proc not readable in the container), or the authenticated branch runs get_detailed_metrics and that helper raises; any exception escapes to the catch-all.

Common situations: Slim Docker images without psutil or host /proc access; read-only root filesystems; a monitoring stack scraping /metrics and alerting on the 500s.

Related errors


AI-assisted analysis of ruvnet/RuView@4685618388 (2026-08-16). Data as JSON: /api/errors/d6bf1852a693bbfd. Report an issue: GitHub.