Add RAM usage in GB and swap metrics to agent, server, UI and CSV export

This commit is contained in:
2026-07-17 17:10:47 +07:00
parent 513b8ede84
commit 76f74201e5
12 changed files with 272 additions and 35 deletions
+32 -5
View File
@@ -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()