From cd4c9a365bb415573b52624a29d09083b956b484 Mon Sep 17 00:00:00 2001 From: Yoni Nakache <45972051+LazyDBA247-Anyvision@users.noreply.github.com> Date: Sun, 23 Feb 2020 22:33:47 +0200 Subject: [PATCH] DiskStats: adding Total & Percent Usage making relevant data visible and readable. --- weed/server/volume_server_ui/templates.go | 40 ++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/weed/server/volume_server_ui/templates.go b/weed/server/volume_server_ui/templates.go index 81496b1de..a2d1dd5bf 100644 --- a/weed/server/volume_server_ui/templates.go +++ b/weed/server/volume_server_ui/templates.go @@ -1,11 +1,29 @@ package master_ui import ( + "fmt" "html/template" "strconv" "strings" ) +func bytesToHumanReadble(b uint64) string { + const unit = 1024 + if b < unit { + return fmt.Sprintf("%d B", b) + } + div, exp := uint64(unit), 0 + for n := b / unit; n >= unit; n /= unit { + div *= unit + exp++ + } + return fmt.Sprintf("%.2f %ciB", float64(b)/float64(div), "KMGTPE"[exp]) +} + +func percentFrom(total uint64, part_of uint64) string { + return fmt.Sprintf("%.2f", (float64(part_of)/float64(total))*100) +} + func join(data []int64) string { var ret []string for _, d := range data { @@ -15,7 +33,9 @@ func join(data []int64) string { } var funcMap = template.FuncMap{ - "join": join, + "join": join, + "bytesToHumanReadble": bytesToHumanReadble, + "percentFrom": percentFrom, } var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(` @@ -57,13 +77,25 @@ var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`
Path | +Total | +Free | +% Usage | +||
---|---|---|---|---|---|
{{ .Dir }} | -{{ .Free }} Bytes Free | +{{ .Dir }} | +{{ bytesToHumanReadble .All }} | +{{ bytesToHumanReadble .Used }} | +{{ percentFrom .All .Used}} |