+
VM
- Resources
+ OS
+ Resources
Disk
State
HTML
vms.each do |vm|
- name = CGI.escapeHTML(vm["name"].to_s)
- os = vm["os"] ? CGI.escapeHTML(vm["os"]) : nil
+ name = CGI.escapeHTML(vm["name"].to_s)
+ os_name = vm["os_name"] ? CGI.escapeHTML(vm["os_name"]) : nil
state = vm["state"].to_s
state_cls = case state
when "running" then "ok"
@@ -151,10 +152,11 @@ if cgi.params.key?("content")
mem_b = vm["memory"].to_i
res = vcpus > 0 || mem_b > 0 ? "#{vcpus} CPU#{vcpus > 1 ? "s" : ""} · #{human_capacity(mem_b)}" : "—"
- cap = vm["disk_total"].to_i
- used = vm["disk_used"].to_i
- dpct_f = cap > 0 ? (used * 100.0 / cap) : 0.0
- dpct = dpct_f.round
+ df = vm["df"] || []
+ cap = df[0].to_i * 1024
+ used = df[1].to_i * 1024
+ dpct_f = cap > 0 ? (used * 100.0 / cap) : 0.0
+ dpct = dpct_f.round
disk_cls = dpct_f >= 90 ? "bad" : dpct_f >= 75 ? "warn" : "ok"
disk_html = if cap > 0
@@ -166,22 +168,35 @@ if cgi.params.key?("content")
%(
—
)
end
- os_html = os ? %(
#{os}
) : ""
+ os_html = os_name ? os_name : ""
+
+ vm_stats = []
+ if updates = vm["updates"]
+ cls = updates == 0 ? "ok" : "warn"
+ vm_stats << [cls, "#{updates} update#{updates == 1 ? "" : "s"}"]
+ end
+ if reboot = vm["reboot_pending"]
+ vm_stats << ["warn", "Reboot pending"]
+ end
+ vm_stats_html = vm_stats.map { |c, txt|
+ %(
#{CGI.escapeHTML(txt)})
+ }.join
+ vm_stats_block = vm_stats.empty? ? "" :
+ %(
#{vm_stats_html}
)
html << <<~HTML
-
+
-
#{CGI.escapeHTML(res)}
+
#{os_html}
+
#{CGI.escapeHTML(res)}
#{disk_html}
#{state_label}
+ #{vm_stats_block}
HTML
end
@@ -281,13 +296,13 @@ if cgi.params.key?("content")
html << %(
File Systems
)
html << %(
)
filesystems.each do |entry|
- mount = CGI.escapeHTML(entry["mount"].to_s)
+ 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
+ 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))