Reorganize cards with server info and file systems in left column

This commit is contained in:
Josh Holtrop 2026-04-20 21:04:09 -04:00
parent 49a20a946f
commit 93c9bf27fa

View File

@ -114,7 +114,7 @@ if cgi.params.key?("content")
vms = info.select { |e| e["type"] == "vm" }
server = info.find { |e| e["type"] == "server" }
html << %(<div class="span-3">)
html << %(<div>)
if server
html << %(<div class="section-label">Server</div>)
@ -173,6 +173,63 @@ if cgi.params.key?("content")
html << %(</div></div>)
end
if filesystems.any?
html << %(<div class="section-label">File Systems</div>)
html << %(<div class="stack">)
filesystems.each do |entry|
mount = CGI.escapeHTML(entry["mount"].to_s)
source = CGI.escapeHTML(entry["source"].to_s)
fstype = CGI.escapeHTML(entry["fstype"].to_s)
size_b = entry["size"].to_i
used_b = entry["used"].to_i
pct_f = size_b > 0 ? (used_b * 100.0 / size_b) : 0.0
pct = pct_f.round
space_cls = pct_f >= 90 ? "bad" : pct_f >= 75 ? "warn" : "ok"
used_h = CGI.escapeHTML(human_capacity(used_b))
size_h = CGI.escapeHTML(human_capacity(size_b))
fs_stats = []
inode_cls = "ok"
if (itot = entry["inode_total"].to_i) > 0
iused = entry["inode_used"].to_i
ipct_f = iused * 100.0 / itot
inode_cls = ipct_f >= 90 ? "bad" : ipct_f >= 75 ? "warn" : "ok"
fs_stats << [inode_cls, "Inodes #{ipct_f.round}%"]
end
fs_stats << ["warn", "READ-ONLY"] if entry["readonly"]
severities = [space_cls, inode_cls]
card_cls = severities.include?("bad") ? "bad" :
severities.include?("warn") ? "warn" : "ok"
stats_html = fs_stats.map { |c, txt|
%(<span class="stat #{c}">#{CGI.escapeHTML(txt)}</span>)
}.join
stats_block = fs_stats.empty? ? "" :
%(<div class="drive-stats" style="margin-top:0.6rem;">#{stats_html}</div>)
html << <<~HTML
<div class="card #{card_cls}">
<div class="card-header">
<span class="card-title">#{mount} <span class="card-capacity">#{fstype}</span></span>
<span class="badge #{space_cls}">#{pct}%</span>
</div>
<div style="display:flex;justify-content:space-between;align-items:center;margin-top:0.5rem;margin-bottom:0.3rem;">
<span style="font-size:0.72rem;color:#64748b;font-weight:600;">#{source}</span>
<span class="subitem-value #{space_cls}">#{used_h} / #{size_h}</span>
</div>
<div class="bar-track" style="height:6px;"><div class="bar-fill #{space_cls}" style="width:#{pct}%"></div></div>
#{stats_block}
</div>
HTML
end
html << %(</div>)
end
html << %(</div>)
html << %(<div class="span-3">)
if vms.any?
running = vms.count { |v| v["state"].to_s == "running" }
total = vms.size
@ -409,61 +466,6 @@ if cgi.params.key?("content")
html << %(</div>)
if filesystems.any?
html << %(<div>)
html << %(<div class="section-label">File Systems</div>)
html << %(<div class="stack">)
filesystems.each do |entry|
mount = CGI.escapeHTML(entry["mount"].to_s)
source = CGI.escapeHTML(entry["source"].to_s)
fstype = CGI.escapeHTML(entry["fstype"].to_s)
size_b = entry["size"].to_i
used_b = entry["used"].to_i
pct_f = size_b > 0 ? (used_b * 100.0 / size_b) : 0.0
pct = pct_f.round
space_cls = pct_f >= 90 ? "bad" : pct_f >= 75 ? "warn" : "ok"
used_h = CGI.escapeHTML(human_capacity(used_b))
size_h = CGI.escapeHTML(human_capacity(size_b))
fs_stats = []
inode_cls = "ok"
if (itot = entry["inode_total"].to_i) > 0
iused = entry["inode_used"].to_i
ipct_f = iused * 100.0 / itot
inode_cls = ipct_f >= 90 ? "bad" : ipct_f >= 75 ? "warn" : "ok"
fs_stats << [inode_cls, "Inodes #{ipct_f.round}%"]
end
fs_stats << ["warn", "READ-ONLY"] if entry["readonly"]
severities = [space_cls, inode_cls]
card_cls = severities.include?("bad") ? "bad" :
severities.include?("warn") ? "warn" : "ok"
stats_html = fs_stats.map { |c, txt|
%(<span class="stat #{c}">#{CGI.escapeHTML(txt)}</span>)
}.join
stats_block = fs_stats.empty? ? "" :
%(<div class="drive-stats" style="margin-top:0.6rem;">#{stats_html}</div>)
html << <<~HTML
<div class="card #{card_cls}">
<div class="card-header">
<span class="card-title">#{mount} <span class="card-capacity">#{fstype}</span></span>
<span class="badge #{space_cls}">#{pct}%</span>
</div>
<div style="display:flex;justify-content:space-between;align-items:center;margin-top:0.5rem;margin-bottom:0.3rem;">
<span style="font-size:0.72rem;color:#64748b;font-weight:600;">#{source}</span>
<span class="subitem-value #{space_cls}">#{used_h} / #{size_h}</span>
</div>
<div class="bar-track" style="height:6px;"><div class="bar-fill #{space_cls}" style="width:#{pct}%"></div></div>
#{stats_block}
</div>
HTML
end
html << %(</div>)
html << %(</div>)
end
cgi.out("type" => "text/html", "charset" => "UTF-8") do
html
end