Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix: Show usable RAIDZ capacity instead of raw pool size

rcourtman49272bd48c58
diff --git a/internal/hostmetrics/zfs.go b/internal/hostmetrics/zfs.go
index 00c17347c3..bb57b419bd 100644
--- a/internal/hostmetrics/zfs.go
+++ b/internal/hostmetrics/zfs.go
@@ -68,22 +68,35 @@ func disksFromZpoolStats(
mp = fmt.Sprintf("zpool:%s", pool)
}
+ ds := bestDatasets[pool]
+
if ok && stat.Size > 0 {
- usage := clampPercent(calculatePercent(stat.Size, stat.Alloc))
+ // For RAIDZ/mirror pools, zpool SIZE is raw capacity (sum of all disks),
+ // but users expect usable capacity (accounting for parity/redundancy).
+ // The dataset's Total (from statfs) gives usable capacity.
+ // Use dataset stats when available and smaller than zpool size. (issue #1052)
+ totalBytes := stat.Size
+ freeBytes := stat.Free
+ if ds.Total > 0 && ds.Total < stat.Size {
+ totalBytes = ds.Total
+ freeBytes = ds.Free
+ }
+
+ usage := clampPercent(calculatePercent(totalBytes, stat.Alloc))
disks = append(disks, agentshost.Disk{
Device: pool,
Mountpoint: mp,
Filesystem: "zfs",
Type: "zfs",
- TotalBytes: int64(stat.Size),
+ TotalBytes: int64(totalBytes),
UsedBytes: int64(stat.Alloc),
- FreeBytes: int64(stat.Free),
+ FreeBytes: int64(freeBytes),
Usage: usage,
})
continue
}
- if ds, ok := bestDatasets[pool]; ok && ds.Total > 0 {
+ if ds.Total > 0 {
usage := clampPercent(calculatePercent(ds.Total, ds.Used))
disks = append(disks, agentshost.Disk{
Device: pool,
diff --git a/internal/hostmetrics/zfs_test.go b/internal/hostmetrics/zfs_test.go
index 740d6f9f82..56b6cd2c7e 100644
--- a/internal/hostmetrics/zfs_test.go
+++ b/internal/hostmetrics/zfs_test.go
@@ -44,6 +44,61 @@ func TestSummarizeZFSPoolsUsesZpoolStats(t *testing.T) {
}
}
+// TestSummarizeZFSPoolsRAIDZCapacity verifies that RAIDZ pools show usable capacity
+// (from dataset stats) rather than raw capacity (from zpool list SIZE). Issue #1052.
+func TestSummarizeZFSPoolsRAIDZCapacity(t *testing.T) {
+ originalQuery := queryZpoolStats
+ t.Cleanup(func() { queryZpoolStats = originalQuery })
+
+ // Simulate a RAIDZ1 pool with 3 disks:
+ // - Raw SIZE from zpool list: 43.6 TB (sum of all disks)
+ // - Usable capacity from statfs: 29 TB (after RAIDZ1 parity overhead)
+ queryZpoolStats = func(ctx context.Context, pools []string) (map[string]zpoolStats, error) {
+ return map[string]zpoolStats{
+ "Main": {Size: 43600000000000, Alloc: 962000000, Free: 43599038000000},
+ }, nil
+ }
+
+ // Dataset stats from statfs reflect usable capacity (29 TB)
+ datasets := []zfsDatasetUsage{
+ {Pool: "Main", Dataset: "Main", Mountpoint: "/mnt/Main", Total: 29000000000000, Used: 962000000, Free: 28999038000000},
+ }
+
+ disks := summarizeZFSPools(context.Background(), datasets)
+ if len(disks) != 1 {
+ t.Fatalf("expected 1 disk, got %d", len(disks))
+ }
+
+ main := disks[0]
+ if main.Device != "Main" {
+ t.Errorf("expected device Main, got %s", main.Device)
+ }
+
+ // Should use usable capacity (29 TB), not raw capacity (43.6 TB)
+ expectedTotal := int64(29000000000000)
+ if main.TotalBytes != expectedTotal {
+ t.Errorf("expected TotalBytes %d (usable capacity), got %d (might be using raw capacity)", expectedTotal, main.TotalBytes)
+ }
+
+ // Used should come from zpool stats (accurate allocation)
+ expectedUsed := int64(962000000)
+ if main.UsedBytes != expectedUsed {
+ t.Errorf("expected UsedBytes %d, got %d", expectedUsed, main.UsedBytes)
+ }
+
+ // Free should use dataset stats when we're using dataset Total
+ expectedFree := int64(28999038000000)
+ if main.FreeBytes != expectedFree {
+ t.Errorf("expected FreeBytes %d, got %d", expectedFree, main.FreeBytes)
+ }
+
+ // Usage should be calculated against usable capacity
+ // 962000000 / 29000000000000 * 100 ≈ 0.003%
+ if main.Usage > 0.1 {
+ t.Errorf("expected usage ~0%%, got %.2f%% (might be calculated against wrong total)", main.Usage)
+ }
+}
+
func TestSummarizeZFSPoolsFallback(t *testing.T) {
originalQuery := queryZpoolStats
t.Cleanup(func() { queryZpoolStats = originalQuery })