Show memory and disk capacity (used/total) on dashboard tiles
Previously the Mem/Disk bars only showed a percentage. Plumbed the underlying byte totals through the whole stack -- collectors, DB (with a migration for the already-deployed CT122 instance), API, and the web tile -- so each card also shows e.g. "19.6/32.0 GB". Verified end-to-end with a throwaway local instance (seeded snapshot, logged in, screenshotted the rendered tile). Note: the SSH-collected hosts (omv, ripper) assume the remote monitor-readonly.sh script emits raw bytes for MEMLINE/DISK_, matching Proxmox's convention -- unverified since that script only lives on those two hosts, not in this repo. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -29,6 +29,10 @@ export function openDb(path: string): Database.Database {
|
||||
cpu_pct REAL,
|
||||
mem_pct REAL,
|
||||
disk_pct REAL,
|
||||
mem_total_bytes REAL,
|
||||
mem_used_bytes REAL,
|
||||
disk_total_bytes REAL,
|
||||
disk_used_bytes REAL,
|
||||
mem_pressure_pct REAL,
|
||||
cpu_pressure_pct REAL,
|
||||
uptime_sec INTEGER,
|
||||
@@ -70,6 +74,15 @@ export function openDb(path: string): Database.Database {
|
||||
is_bootstrap INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
`);
|
||||
// Migration for metric_snapshots pre-dating the raw byte capacity columns
|
||||
// (CREATE TABLE IF NOT EXISTS above doesn't touch already-existing tables).
|
||||
const snapshotColumns = (db.pragma("table_info(metric_snapshots)") as { name: string }[]).map(
|
||||
(c) => c.name
|
||||
);
|
||||
for (const col of ["mem_total_bytes", "mem_used_bytes", "disk_total_bytes", "disk_used_bytes"]) {
|
||||
if (!snapshotColumns.includes(col)) db.exec(`ALTER TABLE metric_snapshots ADD COLUMN ${col} REAL`);
|
||||
}
|
||||
|
||||
// Migration for the devices table pre-dating mdns_hostname (CREATE TABLE IF
|
||||
// NOT EXISTS above doesn't touch already-existing tables). SQLite's ALTER
|
||||
// TABLE ADD COLUMN has no IF NOT EXISTS clause (unlike CREATE TABLE/INDEX),
|
||||
@@ -103,9 +116,11 @@ export function upsertSnapshots(db: Database.Database, snapshots: MetricSnapshot
|
||||
`);
|
||||
const insertSnapshot = db.prepare(`
|
||||
INSERT INTO metric_snapshots
|
||||
(host_id, status, cpu_pct, mem_pct, disk_pct, mem_pressure_pct, cpu_pressure_pct, uptime_sec, meta_json)
|
||||
(host_id, status, cpu_pct, mem_pct, disk_pct, mem_total_bytes, mem_used_bytes,
|
||||
disk_total_bytes, disk_used_bytes, mem_pressure_pct, cpu_pressure_pct, uptime_sec, meta_json)
|
||||
VALUES
|
||||
(@hostId, @status, @cpuPct, @memPct, @diskPct, @memPressurePct, @cpuPressurePct, @uptimeSec, @metaJson)
|
||||
(@hostId, @status, @cpuPct, @memPct, @diskPct, @memTotalBytes, @memUsedBytes,
|
||||
@diskTotalBytes, @diskUsedBytes, @memPressurePct, @cpuPressurePct, @uptimeSec, @metaJson)
|
||||
`);
|
||||
|
||||
const tx = db.transaction((items: MetricSnapshot[]) => {
|
||||
@@ -125,6 +140,10 @@ export interface LatestRow {
|
||||
cpu_pct: number | null;
|
||||
mem_pct: number | null;
|
||||
disk_pct: number | null;
|
||||
mem_total_bytes: number | null;
|
||||
mem_used_bytes: number | null;
|
||||
disk_total_bytes: number | null;
|
||||
disk_used_bytes: number | null;
|
||||
mem_pressure_pct: number | null;
|
||||
cpu_pressure_pct: number | null;
|
||||
uptime_sec: number | null;
|
||||
@@ -136,7 +155,8 @@ export function getLatestSnapshots(db: Database.Database): LatestRow[] {
|
||||
.prepare(
|
||||
`
|
||||
SELECT h.host_id, h.display_name, h.group_name, s.status, s.cpu_pct, s.mem_pct,
|
||||
s.disk_pct, s.mem_pressure_pct, s.cpu_pressure_pct, s.uptime_sec, s.ts
|
||||
s.disk_pct, s.mem_total_bytes, s.mem_used_bytes, s.disk_total_bytes, s.disk_used_bytes,
|
||||
s.mem_pressure_pct, s.cpu_pressure_pct, s.uptime_sec, s.ts
|
||||
FROM hosts h
|
||||
JOIN metric_snapshots s ON s.host_id = h.host_id
|
||||
WHERE s.id = (
|
||||
|
||||
Reference in New Issue
Block a user