agent_tracker/database.py
nickviljoen 1e926da807 Add token tracking, audit filter, and high usage email notifications
- Add audit status filter (Audited/Not Audited) to agent management and admin dashboard
- Add token usage tracking: token_count per timeline entry, total_tokens on agents
- Token badge on agent cards, Total Tokens stat in usage modal, dual-axis chart
- Sort by Total Tokens option, total_tokens in CSV export
- Mailgun email notifications for high token usage (optional, non-blocking)
- Cooldown-based notification tracking in MongoDB token_notifications collection
- Add promote_admin.py utility script for user promotion
- Update CLAUDE.md documentation for all new features

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 21:48:04 +02:00

24 lines
855 B
Python

from motor.motor_asyncio import AsyncIOMotorClient
from dotenv import load_dotenv
import os
load_dotenv()
MONGODB_URI = os.getenv("MONGODB_URI", "mongodb://localhost:27017")
MONGODB_DBNAME = os.getenv("MONGODB_DBNAME", "agenthub_db")
client = AsyncIOMotorClient(MONGODB_URI)
db = client[MONGODB_DBNAME]
users_collection = db.get_collection("users")
agents_collection = db.get_collection("agents")
agent_usage_collection = db.get_collection("agent_usage")
notifications_collection = db.get_collection("token_notifications")
async def check_database_health():
"""Check MongoDB connection health"""
try:
# Attempt to ping the database
await client.admin.command('ping')
return {"status": "connected", "healthy": True}
except Exception as e:
return {"status": "disconnected", "healthy": False, "error": str(e)}