Spaces:
Sleeping
Sleeping
Rifat Azad commited on
Commit ·
fc6d7ac
1
Parent(s): de46e97
test 7
Browse files
logger.py
CHANGED
|
@@ -1,18 +1,22 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
import psutil
|
| 3 |
import httpx
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
@app.get("/")
|
| 8 |
async def read_root():
|
| 9 |
# Get system uptime
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Convert uptime to days, hours, minutes, seconds
|
| 13 |
-
uptime_days,
|
| 14 |
-
uptime_hours,
|
| 15 |
-
uptime_minutes, uptime_seconds = divmod(
|
| 16 |
|
| 17 |
# Get system vitals
|
| 18 |
cpu_percent = psutil.cpu_percent()
|
|
@@ -28,12 +32,12 @@ async def read_root():
|
|
| 28 |
|
| 29 |
return {
|
| 30 |
"System Uptime": {
|
| 31 |
-
"days": uptime_days,
|
| 32 |
-
"hours": uptime_hours,
|
| 33 |
-
"minutes": uptime_minutes,
|
| 34 |
-
"seconds": uptime_seconds
|
| 35 |
},
|
| 36 |
"CPU Usage": f"{cpu_percent}%",
|
| 37 |
"Memory Usage": f"{memory_percent}%",
|
| 38 |
-
"Latency to
|
| 39 |
-
}
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
import psutil
|
| 3 |
import httpx
|
| 4 |
+
import datetime
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
@app.get("/")
|
| 9 |
async def read_root():
|
| 10 |
# Get system uptime
|
| 11 |
+
boot_time = datetime.fromtimestamp(psutil.boot_time())
|
| 12 |
+
current_time = datetime.now()
|
| 13 |
+
uptime_delta = current_time - boot_time
|
| 14 |
+
uptime_seconds = uptime_delta.total_seconds()
|
| 15 |
|
| 16 |
# Convert uptime to days, hours, minutes, seconds
|
| 17 |
+
uptime_days, remainder = divmod(uptime_seconds, 86400)
|
| 18 |
+
uptime_hours, remainder = divmod(remainder, 3600)
|
| 19 |
+
uptime_minutes, uptime_seconds = divmod(remainder, 60)
|
| 20 |
|
| 21 |
# Get system vitals
|
| 22 |
cpu_percent = psutil.cpu_percent()
|
|
|
|
| 32 |
|
| 33 |
return {
|
| 34 |
"System Uptime": {
|
| 35 |
+
"days": int(uptime_days),
|
| 36 |
+
"hours": int(uptime_hours),
|
| 37 |
+
"minutes": int(uptime_minutes),
|
| 38 |
+
"seconds": int(uptime_seconds)
|
| 39 |
},
|
| 40 |
"CPU Usage": f"{cpu_percent}%",
|
| 41 |
"Memory Usage": f"{memory_percent}%",
|
| 42 |
+
"Latency to Google": f"{latency_ms} ms"
|
| 43 |
+
}
|