File size: 2,186 Bytes
69601d4
 
1b179fe
fe1a1e0
69601d4
 
 
6b7ee72
69601d4
 
1b179fe
69601d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe1a1e0
 
 
 
69601d4
6b7ee72
 
 
 
113e70a
6b7ee72
113e70a
6b7ee72
 
69601d4
 
 
 
 
 
 
 
 
1b179fe
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from analyticsHub.routers import authentication, projectManager, dataLoader, reportingTool, utilities, blends, dashboard
from fastapi.middleware.cors import CORSMiddleware
from analyticsHub.utils.functions import getConfig
from api_analytics.fastapi import Analytics
from supabase import create_client
from fastapi import FastAPI
import uvicorn
import psutil
import os

config = getConfig(os.path.join(os.getcwd(), "config.ini"))
client = create_client(
    supabase_url = os.environ["SUPABASE_URL"],
    supabase_key = os.environ["SUPABASE_KEY"]
)

app = FastAPI(
    title = "AnalyticsHub",
    summary = "API Endpoints for AnalyticsHub.",
    version = "1.0",
    root_path = "/api/latest",
    docs_url = "/documentation/docs",
    redoc_url = "/documentation/redoc"
)

app.add_middleware(
    CORSMiddleware,
    allow_origins = ["*"],
    allow_credentials = True,
    allow_methods = ["*"],
    allow_headers = ["*"],
)
app.add_middleware(
    Analytics,
    api_key = os.environ["FASTAPI_ANALYTICS_KEY"]
)

@app.on_event("startup")
async def stats():
    memory = psutil.virtual_memory()
    cpu_usage = psutil.cpu_percent(interval=1, percpu=True)
    totalUsage = psutil.cpu_percent(interval=1)
    print(f"RAM Usage Percentage: {memory.percent}%")
    print(f"Total CPU Utilization: {totalUsage}%")
    print(f"Total CPU Usage Per Core: {cpu_usage}")

app.include_router(authentication.router, prefix = "/auth", tags = ["Authentication"])
app.include_router(projectManager.router, prefix = "/projects", tags = ["Project Management"])
app.include_router(dataLoader.router, prefix = "/loaders", tags = ["Data Loader"])
app.include_router(blends.router, prefix = "/blends", tags = ["Blends"])
app.include_router(reportingTool.router, prefix = "/reportingTool", tags = ["Reporting Tool"])
app.include_router(dashboard.router, prefix = "/dashboard", tags = ["Dashboard"])
app.include_router(utilities.router, prefix = "/utils", tags = ["Utilities"])

if __name__ == "__main__":
    uvicorn.run(
        "app:app",
        host = config.get("APPLICATION", "host"),
        port = config.getint("APPLICATION", "port"),
        workers = config.getint("APPLICATION", "workers")
    )