Spaces:
Sleeping
Sleeping
Create modules/diagnostics.py
Browse files- modules/diagnostics.py +56 -0
modules/diagnostics.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# modules/diagnostics.py - System Diagnostics Module
|
| 2 |
+
from fastapi import APIRouter
|
| 3 |
+
import psutil
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
|
| 6 |
+
def register_module(app, client, username):
|
| 7 |
+
"""Register diagnostics module with FastAPI app"""
|
| 8 |
+
router = APIRouter()
|
| 9 |
+
|
| 10 |
+
@router.get("/diagnostics/health")
|
| 11 |
+
async def diagnostics_health():
|
| 12 |
+
"""Basic system health check"""
|
| 13 |
+
cpu = psutil.cpu_percent()
|
| 14 |
+
memory = psutil.virtual_memory()
|
| 15 |
+
|
| 16 |
+
return {
|
| 17 |
+
"module": "diagnostics",
|
| 18 |
+
"status": "active",
|
| 19 |
+
"system": {
|
| 20 |
+
"cpu_usage": cpu,
|
| 21 |
+
"memory_used": memory.percent,
|
| 22 |
+
"memory_available": memory.available / (1024**3), # GB
|
| 23 |
+
"timestamp": datetime.now().isoformat()
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
@router.get("/diagnostics/full")
|
| 28 |
+
async def full_diagnostics():
|
| 29 |
+
"""Complete system diagnostics"""
|
| 30 |
+
try:
|
| 31 |
+
from modules.orchestrator import get_system_diagnostics
|
| 32 |
+
return await get_system_diagnostics()
|
| 33 |
+
except ImportError:
|
| 34 |
+
return {
|
| 35 |
+
"module": "diagnostics",
|
| 36 |
+
"status": "fallback",
|
| 37 |
+
"message": "Using basic diagnostics",
|
| 38 |
+
"basic_metrics": {
|
| 39 |
+
"cpu": psutil.cpu_percent(),
|
| 40 |
+
"memory": psutil.virtual_memory().percent,
|
| 41 |
+
"disk": psutil.disk_usage('/').percent
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
app.include_router(router)
|
| 46 |
+
print("✅ Diagnostics module registered with FastAPI")
|
| 47 |
+
|
| 48 |
+
# Export function for direct imports
|
| 49 |
+
async def get_basic_metrics():
|
| 50 |
+
"""Get basic system metrics"""
|
| 51 |
+
return {
|
| 52 |
+
"cpu": psutil.cpu_percent(),
|
| 53 |
+
"memory": psutil.virtual_memory().percent,
|
| 54 |
+
"disk": psutil.disk_usage('/').percent,
|
| 55 |
+
"timestamp": datetime.now().isoformat()
|
| 56 |
+
}
|