agent_tracker/database.py
2025-08-17 07:23:53 -05:00

23 lines
787 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")
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)}