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.

Prefer the root-mounted dataset for ZFS pool summaries

rcourtman6b5f57a86638
diff --git a/internal/hostmetrics/zfs.go b/internal/hostmetrics/zfs.go
index c2209e2ef4..9ebd7ea2f0 100644
--- a/internal/hostmetrics/zfs.go
+++ b/internal/hostmetrics/zfs.go
@@ -455,14 +455,20 @@ func bestZFSMountpoints(datasets []zfsDatasetUsage) map[string]string {
}
func zfsMountpointScore(ds zfsDatasetUsage) int {
- if ds.Dataset != "" && !strings.Contains(ds.Dataset, "/") {
+ // A dataset actually mounted at "/" is the best representative of the pool,
+ // even if it is a child dataset (e.g. rpool/ROOT/pve-1), so it must outrank a
+ // pool-root dataset mounted elsewhere (e.g. rpool at /mnt/storage).
+ if strings.TrimSpace(ds.Mountpoint) == "/" {
return 0
}
+ if ds.Dataset != "" && !strings.Contains(ds.Dataset, "/") {
+ return 1
+ }
path := strings.Trim(ds.Mountpoint, "/")
if path == "" {
- return 1
+ return 0
}
- return 1 + strings.Count(path, "/")
+ return 2 + strings.Count(path, "/")
}
func zfsPoolFromDevice(device string) string {
diff --git a/internal/hostmetrics/zfs_test.go b/internal/hostmetrics/zfs_test.go
index 9528fe94b8..1f1d1a23ae 100644
--- a/internal/hostmetrics/zfs_test.go
+++ b/internal/hostmetrics/zfs_test.go
@@ -665,6 +665,14 @@ func TestBestZFSMountpoints(t *testing.T) {
},
want: map[string]string{"rpool": "/"},
},
+ {
+ name: "root mountpoint beats pool root mounted elsewhere",
+ datasets: []zfsDatasetUsage{
+ {Pool: "rpool", Dataset: "rpool", Mountpoint: "/mnt/storage"},
+ {Pool: "rpool", Dataset: "rpool/ROOT/pve-1", Mountpoint: "/"},
+ },
+ want: map[string]string{"rpool": "/"},
+ },
{
name: "skip empty pool",
datasets: []zfsDatasetUsage{
@@ -723,39 +731,39 @@ func TestZfsMountpointScore(t *testing.T) {
want int
}{
{
- name: "root dataset gets score 0",
- ds: zfsDatasetUsage{Dataset: "tank", Mountpoint: "/tank"},
+ name: "root mountpoint gets score 0",
+ ds: zfsDatasetUsage{Dataset: "rpool/ROOT/ubuntu", Mountpoint: "/"},
want: 0,
},
{
- name: "child dataset at root mountpoint",
- ds: zfsDatasetUsage{Dataset: "rpool/ROOT/ubuntu", Mountpoint: "/"},
- want: 1, // path empty after trim("/"), returns 1
+ name: "root dataset mounted elsewhere gets score 1",
+ ds: zfsDatasetUsage{Dataset: "tank", Mountpoint: "/tank"},
+ want: 1,
},
{
name: "child dataset shallow path",
ds: zfsDatasetUsage{Dataset: "tank/data", Mountpoint: "/data"},
- want: 1, // path="data" has 0 slashes, 1+0=1
+ want: 2, // non-root mountpoints rank after / and pool root datasets
},
{
name: "child dataset deep path",
ds: zfsDatasetUsage{Dataset: "tank/a/b/c", Mountpoint: "/a/b/c"},
- want: 3, // path="a/b/c" has 2 slashes, 1+2=3
+ want: 4, // path="a/b/c" has 2 slashes, 2+2=4
},
{
name: "empty dataset falls through to path scoring",
ds: zfsDatasetUsage{Dataset: "", Mountpoint: "/tank"},
- want: 1, // empty dataset passes first check, path="tank" has 0 slashes, 1+0=1
+ want: 2, // empty dataset passes first check, path="tank" has 0 slashes, 2+0=2
},
{
name: "trailing slash stripped from mountpoint",
ds: zfsDatasetUsage{Dataset: "tank/data", Mountpoint: "/data/"},
- want: 1, // path="data" has 0 slashes, 1+0=1
+ want: 2, // path="data" has 0 slashes, 2+0=2
},
{
name: "very deep mountpoint",
ds: zfsDatasetUsage{Dataset: "tank/deep", Mountpoint: "/a/b/c/d/e"},
- want: 5, // path="a/b/c/d/e" has 4 slashes, 1+4=5
+ want: 6, // path="a/b/c/d/e" has 4 slashes, 2+4=6
},
}