File size: 553 Bytes
2a8447c
579426e
42301fa
04c3cba
 
7d391f9
04c3cba
 
579426e
04c3cba
579426e
7d391f9
579426e
 
 
 
 
 
 
 
 
 
 
 
04c3cba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from fastapi import FastAPI, Query
import os
from typing import Any, Optional

app = FastAPI(
    title="Test"
)


@app.get("/")
def root(
    show_info: Optional[str] = Query(
        False,
        description='True/False depending your needs, gets average CPU load value',
        regex='^(True|False)$')
) -> Any:
    result: Dict[Any, Any] = {
        "message": "Your first endpoint is working"
    }

    if cpu_load == 'True':
        result["cpu_average_load"] = os.getloadavg()
        result["cpu"] = os.cpu_count()
        
    return result