Browse Source

DiskStats: adding Total & Percent Usage

making relevant data visible and readable.
pull/1206/head
Yoni Nakache 5 years ago
committed by GitHub
parent
commit
cd4c9a365b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 38
      weed/server/volume_server_ui/templates.go

38
weed/server/volume_server_ui/templates.go

@ -1,11 +1,29 @@
package master_ui package master_ui
import ( import (
"fmt"
"html/template" "html/template"
"strconv" "strconv"
"strings" "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 { func join(data []int64) string {
var ret []string var ret []string
for _, d := range data { for _, d := range data {
@ -16,6 +34,8 @@ func join(data []int64) string {
var funcMap = template.FuncMap{ var funcMap = template.FuncMap{
"join": join, "join": join,
"bytesToHumanReadble": bytesToHumanReadble,
"percentFrom": percentFrom,
} }
var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOCTYPE html> var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOCTYPE html>
@ -57,13 +77,25 @@ var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOC
<div class="row"> <div class="row">
<div class="col-sm-6"> <div class="col-sm-6">
<h2>Disk Stats</h2> <h2>Disk Stats</h2>
<table class="table table-condensed table-striped">
<table class="table table-striped">
<thead>
<tr>
<th>Path</th>
<th>Total</th>
<th>Free</th>
<th>% Usage</th>
</tr>
</thead>
<tbody>
{{ range .DiskStatuses }} {{ range .DiskStatuses }}
<tr> <tr>
<th>{{ .Dir }}</th>
<td>{{ .Free }} Bytes Free</td>
<td>{{ .Dir }}</td>
<td>{{ bytesToHumanReadble .All }}</td>
<td>{{ bytesToHumanReadble .Used }}</td>
<td>{{ percentFrom .All .Used}}</td>
</tr> </tr>
{{ end }} {{ end }}
</tbody>
</table> </table>
</div> </div>

Loading…
Cancel
Save