Complete backend verification: fix syntax errors, create __init__.py files, add setup_db.py, update docker-compose for two PostgreSQL containers
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
MTG Database Monitor
|
||||
|
||||
Monitors PostgreSQL database metrics for both cockatrice and mtgdata databases.
|
||||
Monitors PostgreSQL database metrics for both mtgonline and mtgdata databases.
|
||||
Tracks:
|
||||
- Database size and growth
|
||||
- Table sizes
|
||||
@@ -28,14 +28,14 @@ MTG_DB = settings.MTG_DATABASE_URL
|
||||
class MtgMonitor:
|
||||
def __init__(self):
|
||||
self.mtg_conn = None
|
||||
self.cockatrice_conn = None
|
||||
self.mtgonline_conn = None
|
||||
self.metrics = {}
|
||||
|
||||
async def connect(self):
|
||||
"""Establish connections to both databases."""
|
||||
try:
|
||||
self.mtg_conn = await asyncpg.connect(MTG_DB)
|
||||
self.cockatrice_conn = await asyncpg.connect(COCKATRICE_DB)
|
||||
self.mtgonline_conn = await asyncpg.connect(COCKATRICE_DB)
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"Connection error: {e}")
|
||||
@@ -45,8 +45,8 @@ class MtgMonitor:
|
||||
"""Close database connections."""
|
||||
if self.mtg_conn:
|
||||
await self.mtg_conn.close()
|
||||
if self.cockatrice_conn:
|
||||
await self.cockatrice_conn.close()
|
||||
if self.mtgonline_conn:
|
||||
await self.mtgonline_conn.close()
|
||||
|
||||
async def get_database_size(self) -> Dict[str, float]:
|
||||
"""Get size of databases in GB."""
|
||||
@@ -56,14 +56,14 @@ class MtgMonitor:
|
||||
SELECT pg_database_size(current_database()) as size
|
||||
""")
|
||||
|
||||
# Cockatrice database size
|
||||
cockatrice_size = await self.cockatrice_conn.fetchval("""
|
||||
# MTG Online database size
|
||||
mtgonline_size = await self.mtgonline_conn.fetchval("""
|
||||
SELECT pg_database_size(current_database()) as size
|
||||
""")
|
||||
|
||||
return {
|
||||
"mtgdata": mtg_size / (1024**3), # Convert to GB
|
||||
"cockatrice": cockatrice_size / (1024**3)
|
||||
"mtgonline": mtgonline_size / (1024**3)
|
||||
}
|
||||
except Exception as e:
|
||||
print(f"Error getting database sizes: {e}")
|
||||
|
||||
Reference in New Issue
Block a user