Add RAM usage in GB and swap metrics to agent, server, UI and CSV export
This commit is contained in:
+32
-5
@@ -39,10 +39,37 @@ def run_migrations():
|
||||
conn.execute(text("ALTER TABLE audit_log ADD COLUMN username TEXT"))
|
||||
conn.commit()
|
||||
|
||||
# Heartbeat: add sessions column if missing
|
||||
# Heartbeat: add missing columns
|
||||
if "heartbeats" in insp.get_table_names():
|
||||
hb_cols = {c["name"] for c in insp.get_columns("heartbeats")}
|
||||
if "sessions" not in hb_cols:
|
||||
with engine.connect() as conn:
|
||||
conn.execute(text("ALTER TABLE heartbeats ADD COLUMN sessions TEXT"))
|
||||
conn.commit()
|
||||
new_hb_cols = [
|
||||
("sessions", "TEXT"),
|
||||
("ram_used_gb", "REAL"),
|
||||
("ram_available_gb", "REAL"),
|
||||
("swap_total_gb", "REAL"),
|
||||
("swap_used_gb", "REAL"),
|
||||
("swap_free_gb", "REAL"),
|
||||
("swap_percent", "REAL"),
|
||||
]
|
||||
with engine.connect() as conn:
|
||||
for col, col_type in new_hb_cols:
|
||||
if col not in hb_cols:
|
||||
conn.execute(text(f"ALTER TABLE heartbeats ADD COLUMN {col} {col_type}"))
|
||||
conn.commit()
|
||||
|
||||
# Computer: add missing columns
|
||||
if "computers" in insp.get_table_names():
|
||||
pc_cols = {c["name"] for c in insp.get_columns("computers")}
|
||||
new_pc_cols = [
|
||||
("current_ram_used_gb", "REAL"),
|
||||
("current_ram_available_gb", "REAL"),
|
||||
("current_swap_total_gb", "REAL"),
|
||||
("current_swap_used_gb", "REAL"),
|
||||
("current_swap_free_gb", "REAL"),
|
||||
("current_swap_percent", "REAL"),
|
||||
]
|
||||
with engine.connect() as conn:
|
||||
for col, col_type in new_pc_cols:
|
||||
if col not in pc_cols:
|
||||
conn.execute(text(f"ALTER TABLE computers ADD COLUMN {col} {col_type}"))
|
||||
conn.commit()
|
||||
|
||||
Reference in New Issue
Block a user