44Desenvolvida com FastAPI e Pydantic v2.
55"""
66
7- from fastapi import FastAPI
7+ import time
88from contextlib import asynccontextmanager
99
10+ from fastapi import FastAPI
11+
1012from bot_report_api .routers import bots , execucoes , relatorios
11- from bot_report_api .database import inicializar_db
13+ from bot_report_api .database import inicializar_db , listar_bots , listar_execucoes
14+ from bot_report_api .schemas import StatusExecucao
15+
16+ _startup_time = time .time ()
1217
1318
1419@asynccontextmanager
@@ -22,7 +27,8 @@ async def lifespan(app: FastAPI):
2227 title = "Bot Report API" ,
2328 description = (
2429 "API REST para cadastro de bots, registro de execuções e "
25- "consulta de relatórios de automação."
30+ "consulta de relatórios de automação.\n \n "
31+ "**Documentação:** `/docs` | **OpenAPI JSON:** `/openapi.json`"
2632 ),
2733 version = "0.1.0" ,
2834 lifespan = lifespan ,
@@ -33,7 +39,32 @@ async def lifespan(app: FastAPI):
3339app .include_router (relatorios .router , prefix = "/relatorios" , tags = ["Relatórios" ])
3440
3541
36- @app .get ("/" , tags = ["Health" ] )
42+ @app .get ("/health " , tags = ["Observabilidade" ], summary = "Health check" )
3743def health_check ():
38- """Verifica se a API está no ar."""
39- return {"status" : "ok" , "versao" : "0.1.0" }
44+ """Verifica se a API está operacional — retorna status, versão e uptime."""
45+ return {
46+ "status" : "ok" ,
47+ "versao" : "0.1.0" ,
48+ "uptime_segundos" : round (time .time () - _startup_time , 1 ),
49+ }
50+
51+
52+ @app .get ("/metrics" , tags = ["Observabilidade" ], summary = "Métricas da aplicação" )
53+ def metricas ():
54+ """Retorna métricas operacionais em tempo real para monitoramento."""
55+ todas_execucoes = listar_execucoes ()
56+ return {
57+ "total_bots" : len (listar_bots ()),
58+ "total_execucoes" : len (todas_execucoes ),
59+ "execucoes_por_status" : {
60+ status .value : sum (1 for e in todas_execucoes if e .status == status )
61+ for status in StatusExecucao
62+ },
63+ "uptime_segundos" : round (time .time () - _startup_time , 1 ),
64+ "versao" : "0.1.0" ,
65+ }
66+
67+
68+ @app .get ("/" , include_in_schema = False )
69+ def root ():
70+ return {"mensagem" : "Bot Report API — acesse /docs para a documentação." }
0 commit comments