New version with grafana
This commit is contained in:
parent
f86ad9a542
commit
b2f649a489
6 changed files with 201 additions and 21 deletions
38
main.py
38
main.py
|
|
@ -381,12 +381,44 @@ async def ws_live_updates(websocket: WebSocket):
|
|||
browser_conns.remove(websocket)
|
||||
|
||||
|
||||
# -------------------- static frontend ---------------------------
|
||||
# static frontend
|
||||
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
||||
## -------------------- static frontend ---------------------------
|
||||
## (static mount moved to end of file, below API routes)
|
||||
|
||||
# list routes for convenience
|
||||
print("🔍 Registered routes:")
|
||||
for route in app.routes:
|
||||
if isinstance(route, APIRoute):
|
||||
print(f"{route.path} -> {route.methods}")
|
||||
# Add stats endpoint for per-character metrics
|
||||
@app.get("/stats/{character_name}")
|
||||
async def get_stats(character_name: str):
|
||||
"""Return latest telemetry snapshot and aggregates for a specific character."""
|
||||
# Latest snapshot
|
||||
sql_snap = (
|
||||
"SELECT * FROM telemetry_events "
|
||||
"WHERE character_name = :cn "
|
||||
"ORDER BY timestamp DESC LIMIT 1"
|
||||
)
|
||||
snap = await database.fetch_one(sql_snap, {"cn": character_name})
|
||||
if not snap:
|
||||
raise HTTPException(status_code=404, detail="Character not found")
|
||||
snap_dict = dict(snap)
|
||||
# Total kills
|
||||
sql_kills = "SELECT total_kills FROM char_stats WHERE character_name = :cn"
|
||||
row_kills = await database.fetch_one(sql_kills, {"cn": character_name})
|
||||
total_kills = row_kills["total_kills"] if row_kills else 0
|
||||
# Total rares
|
||||
sql_rares = "SELECT total_rares FROM rare_stats WHERE character_name = :cn"
|
||||
row_rares = await database.fetch_one(sql_rares, {"cn": character_name})
|
||||
total_rares = row_rares["total_rares"] if row_rares else 0
|
||||
result = {
|
||||
"character_name": character_name,
|
||||
"latest_snapshot": snap_dict,
|
||||
"total_kills": total_kills,
|
||||
"total_rares": total_rares,
|
||||
}
|
||||
return JSONResponse(content=jsonable_encoder(result))
|
||||
|
||||
# -------------------- static frontend ---------------------------
|
||||
# Serve SPA files (catch-all for frontend routes)
|
||||
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue