Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from fastapi.middleware.gzip import GZipMiddleware
|
|
3 |
from fastapi.responses import FileResponse
|
4 |
import os
|
5 |
import shutil
|
|
|
6 |
|
7 |
app = FastAPI()
|
8 |
|
@@ -26,3 +27,26 @@ async def download_file(filename: str):
|
|
26 |
if os.path.exists(file_path):
|
27 |
return FileResponse(file_path, media_type='application/octet-stream', filename=filename)
|
28 |
return {"error": "File not found"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from fastapi.responses import FileResponse
|
4 |
import os
|
5 |
import shutil
|
6 |
+
import psutil
|
7 |
|
8 |
app = FastAPI()
|
9 |
|
|
|
27 |
if os.path.exists(file_path):
|
28 |
return FileResponse(file_path, media_type='application/octet-stream', filename=filename)
|
29 |
return {"error": "File not found"}
|
30 |
+
|
31 |
+
@app.get("/system/metrics")
|
32 |
+
async def get_system_metrics():
|
33 |
+
cpu_load = psutil.cpu_percent(interval=1)
|
34 |
+
memory = psutil.virtual_memory()
|
35 |
+
disk_usage = psutil.disk_usage('/')
|
36 |
+
|
37 |
+
metrics = {
|
38 |
+
"cpu_load": cpu_load,
|
39 |
+
"memory": {
|
40 |
+
"total": memory.total,
|
41 |
+
"available": memory.available,
|
42 |
+
"used": memory.used,
|
43 |
+
"percent": memory.percent
|
44 |
+
},
|
45 |
+
"disk_usage": {
|
46 |
+
"total": disk_usage.total,
|
47 |
+
"used": disk_usage.used,
|
48 |
+
"free": disk_usage.free,
|
49 |
+
"percent": disk_usage.percent
|
50 |
+
}
|
51 |
+
}
|
52 |
+
return metrics
|