added server tracking plus server metrics
This commit is contained in:
parent
80a0a16bab
commit
ca12f4807b
5 changed files with 567 additions and 6 deletions
35
db_async.py
35
db_async.py
|
|
@ -126,6 +126,41 @@ character_inventories = Table(
|
|||
UniqueConstraint("character_name", "item_id", name="uq_char_item"),
|
||||
)
|
||||
|
||||
# Server health monitoring tables
|
||||
server_health_checks = Table(
|
||||
# Time-series data for server health checks
|
||||
"server_health_checks",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True),
|
||||
Column("server_name", String, nullable=False, index=True),
|
||||
Column("server_address", String, nullable=False),
|
||||
Column("timestamp", DateTime(timezone=True), nullable=False, default=sqlalchemy.func.now()),
|
||||
Column("status", String(10), nullable=False), # 'up' or 'down'
|
||||
Column("latency_ms", Float, nullable=True),
|
||||
Column("player_count", Integer, nullable=True),
|
||||
)
|
||||
|
||||
server_status = Table(
|
||||
# Current server status and uptime tracking
|
||||
"server_status",
|
||||
metadata,
|
||||
Column("server_name", String, primary_key=True),
|
||||
Column("current_status", String(10), nullable=False),
|
||||
Column("last_seen_up", DateTime(timezone=True), nullable=True),
|
||||
Column("last_restart", DateTime(timezone=True), nullable=True),
|
||||
Column("total_uptime_seconds", BigInteger, default=0),
|
||||
Column("last_check", DateTime(timezone=True), nullable=True),
|
||||
Column("last_latency_ms", Float, nullable=True),
|
||||
Column("last_player_count", Integer, nullable=True),
|
||||
)
|
||||
|
||||
# Index for efficient server health check queries
|
||||
Index(
|
||||
'ix_server_health_checks_name_ts',
|
||||
server_health_checks.c.server_name,
|
||||
server_health_checks.c.timestamp.desc()
|
||||
)
|
||||
|
||||
async def init_db_async():
|
||||
"""Initialize PostgreSQL/TimescaleDB schema and hypertable.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue