Files
seaweedfs/weed/admin/view/app/admin_render_test.go
T
Chris LuandClaude Opus 5.5 7beac0e8ea admin: show disk usage on the dashboard instead of the data size (#12466)
* admin: show disk usage on the dashboard instead of the data size

The dashboard's Total Size card summed the volume and EC shard sizes the
volume servers report. That leaves out deleted needles waiting for vacuum,
EC generations kept after a vacuum, and anything else on the disks, so on a
cluster with a lot of EC vacuum activity it showed far less than the disks
held.

The card now shows the bytes in use on the volume servers' disks, the same
statfs numbers the volume server list uses, with the disks' capacity, and
its trend line follows that number. Servers that report no statfs numbers
count their data size, as on the volume server list.

Claude-Session: https://claude.ai/code/session_011UpvafcfUuC2mLxNAXLQJi

* admin: compute the disk usage percentage in float64

current*100 overflows int64 past about 92 PB of used space, so the
dashboard card showed a negative percentage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* admin: size the volume server disk bar with calculatePercent64

int(host.DiskUsage) truncates byte counts on 32-bit builds, so the bar
width was wrong for any disk over 2 GB there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* admin: test the cluster disk totals across statfs and fallback servers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 19:25:10 -08:00

42 lines
1.1 KiB
Go

package app
import (
"bytes"
"context"
"strings"
"testing"
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
)
// The size card reports the bytes in use on the volume servers' disks, which
// is what fills them, rather than the size of the data they hold.
func TestAdminDashboardShowsDiskUsage(t *testing.T) {
const tib = int64(1) << 40
data := dash.AdminData{
TotalSize: 276 * tib,
DiskUsage: 348 * tib,
DiskCapacity: 1000 * tib,
}
var buf bytes.Buffer
if err := Admin(data).Render(context.Background(), &buf); err != nil {
t.Fatalf("render: %v", err)
}
got := buf.String()
for _, want := range []string{"Disk Usage", "348.0 TB", "of 1000.0 TB (34%)"} {
if !strings.Contains(got, want) {
t.Errorf("dashboard is missing %q", want)
}
}
if strings.Contains(got, "276.0 TB") {
t.Error("dashboard still shows the logical data size")
}
}
func TestCalculatePercent64PetabyteScale(t *testing.T) {
const pib = int64(1) << 50
if got := calculatePercent64(100*pib, 200*pib); got != 50 {
t.Errorf("100 of 200 PiB = %d%%, want 50%%", got)
}
}