Rifat Azad commited on
Commit
ed727a6
·
1 Parent(s): 14aed84

system health

Browse files
Files changed (1) hide show
  1. logger.py +35 -1
logger.py CHANGED
@@ -1,7 +1,41 @@
1
  from fastapi import FastAPI
 
 
2
 
3
  app = FastAPI()
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  @app.get("/")
6
  async def read_root():
7
- return {"PyDVPL DISCORD BOT DOCKER"}
 
 
1
  from fastapi import FastAPI
2
+ import psutil
3
+ import time
4
 
5
  app = FastAPI()
6
 
7
+ # Endpoint to get system health
8
+ @app.get("/health")
9
+ async def get_system_health():
10
+ cpu_percent = psutil.cpu_percent()
11
+ memory_percent = psutil.virtual_memory().percent
12
+ disk_percent = psutil.disk_usage('/').percent
13
+ return {
14
+ "cpu_percent": cpu_percent,
15
+ "memory_percent": memory_percent,
16
+ "disk_percent": disk_percent
17
+ }
18
+
19
+ # Endpoint to get server stats
20
+ start_time = time.time()
21
+
22
+ @app.get("/stats")
23
+ async def get_server_stats():
24
+ uptime_seconds = time.time() - start_time
25
+ uptime_minutes = uptime_seconds / 60
26
+ return {
27
+ "uptime_seconds": uptime_seconds,
28
+ "uptime_minutes": uptime_minutes,
29
+ # You can add more stats here like number of requests served, etc.
30
+ }
31
+
32
+ # Ping endpoint
33
+ @app.get("/ping")
34
+ async def ping():
35
+ return {"ping": "pong"}
36
+
37
+ # Root endpoint
38
  @app.get("/")
39
  async def read_root():
40
+ return {"PyDVPL DISCORD BOT DOCKER"}
41
+