system-status: show storage usage (DB, attachments, backups, disk free) — v0.1.0:63

/api/system/status now returns a best-effort storage block: database file size
(crm.db + WAL + SHM), the email_attachments dir, the backups dir, and disk
total/used/free via shutil.disk_usage(DATA_DIR). System Status renders a Storage
section with human-readable sizes so growth can be watched over time.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Keysat
2026-06-06 13:34:18 -05:00
parent ea036f49a6
commit 3893a4fb9f
5 changed files with 87 additions and 4 deletions
+32
View File
@@ -3601,6 +3601,38 @@ class CRMHandler(BaseHTTPRequestHandler):
}
except Exception:
out['source_counts'] = None
# Storage usage — DB file(s), email attachments, backups, and disk headroom,
# so growth can be watched over time. Best-effort; never fails the status call.
try:
import shutil
def _fsize(p):
try:
return os.path.getsize(p)
except OSError:
return 0
def _dirsize(d):
total = 0
for root, _dirs, files in os.walk(d):
for f in files:
try:
total += os.path.getsize(os.path.join(root, f))
except OSError:
pass
return total
du = shutil.disk_usage(DATA_DIR)
out['storage'] = {
'database_bytes': sum(_fsize(DB_PATH + s) for s in ("", "-wal", "-shm")),
'attachments_bytes': _dirsize(os.path.join(DATA_DIR, "email_attachments")),
'backups_bytes': _dirsize(os.path.join(DATA_DIR, "backups")),
'disk_total_bytes': du.total,
'disk_used_bytes': du.used,
'disk_free_bytes': du.free,
}
except Exception:
out['storage'] = None
conn.close()
self.send_json({"data": out})