tqhoa commited on
Commit
579426e
·
1 Parent(s): 9e06eae

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +19 -2
main.py CHANGED
@@ -1,11 +1,28 @@
1
  from fastapi import FastAPI
 
2
 
3
 
4
  app = FastAPI(
5
  title="Test Selenium"
6
  )
7
 
 
8
  @app.get("/")
9
- def root ():
10
- result = {message: "This is test"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  return result
 
1
  from fastapi import FastAPI
2
+ import os
3
 
4
 
5
  app = FastAPI(
6
  title="Test Selenium"
7
  )
8
 
9
+
10
  @app.get("/")
11
+ def root(
12
+ cpu_load: Optional[str] = Query(
13
+ False,
14
+ description='True/False depending your needs, gets average CPU load value',
15
+ regex='^(True|False)$')
16
+ ) -> Any:
17
+ result: Dict[Any, Any] = {
18
+ "message": "Your first endpoint is working"
19
+ }
20
+
21
+ if cpu_load == 'True':
22
+ result["cpu_average_load"] = os.getloadavg()
23
+ result["cpu"] = os.cpu_count()
24
+
25
+ mem_bytes = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
26
+ result["memory"] = mem_bytes/(1024)
27
+
28
  return result