{"record":{"id":"d6bf1852a693bbfd","repo":"ruvnet/RuView","slug":"failed-to-get-system-metrics-str-e","errorCode":null,"errorMessage":"Failed to get system metrics: {str(e)}","messagePattern":"Failed to get system metrics: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"archive/v1/src/api/routers/health.py","lineNumber":281,"sourceCode":"    current_user: Optional[Dict] = Depends(get_current_user)\n):\n    \"\"\"Get detailed system metrics.\"\"\"\n    try:\n        metrics = await asyncio.to_thread(get_system_metrics)\n        \n        # Add additional metrics if authenticated\n        if current_user:\n            detailed = await asyncio.to_thread(get_detailed_metrics)\n            metrics.update(detailed)\n        \n        return {\n            \"timestamp\": datetime.utcnow().isoformat(),\n            \"metrics\": metrics\n        }\n        \n    except Exception as e:\n        logger.error(f\"Error getting system metrics: {e}\")\n        raise HTTPException(\n            status_code=500,\n            detail=f\"Failed to get system metrics: {str(e)}\"\n        )\n\n\n@router.get(\"/version\")\nasync def get_version_info():\n    \"\"\"Get application version information.\"\"\"\n    settings = get_settings()\n    \n    return {\n        \"name\": settings.app_name,\n        \"version\": settings.version,\n        \"environment\": settings.environment,\n        \"debug\": settings.debug,\n        \"timestamp\": datetime.utcnow().isoformat()\n    }\n","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/archive/v1/src/api/routers/health.py#L263-L299","documentation":"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.","triggerScenarios":"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.","commonSituations":"Slim Docker images without psutil or host /proc access; read-only root filesystems; a monitoring stack scraping /metrics and alerting on the 500s.","solutions":["Check the server log for 'Error getting system metrics:' to get the real exception","Install/permit the metrics dependency and give the process read access to /proc","Degrade instead of 500: return basic metrics with an 'unavailable' marker when detailed collection fails","Remember the detailed branch only runs when authenticated — most scrapers call unauthenticated"],"exampleFix":"# before\ndetailed = await asyncio.to_thread(get_detailed_metrics)\nmetrics.update(detailed)\n\n# after\ntry:\n    detailed = await asyncio.to_thread(get_detailed_metrics)\n    metrics.update(detailed)\nexcept Exception:\n    logger.exception('detailed metrics unavailable')\n    metrics['detailed'] = 'unavailable'","handlingStrategy":"fallback","validationCode":"try:\n    metrics = (await client.get('/metrics', timeout=5)).json()\nexcept Exception:\n    metrics = None\nif metrics is None:\n    logger.warning('metrics unavailable; continuing without them')","typeGuard":null,"tryCatchPattern":"try:\n    payload = (await client.get('/metrics')).json()\nexcept Exception:\n    payload = {'timestamp': None, 'metrics': {}}\n# dashboards render unknowns when metrics are missing","preventionTips":["Treat /metrics as best-effort; never gate core flows on it","Verify the runtime image has psutil installed and /proc readable","Remember detailed metrics require an authenticated token"],"tags":["python","fastapi","http-500","observability","system-metrics"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}