Lightweight server monitoring with historical data, docker stats, and alerts.
feat: surface zpool status messages in pool health (#2509)
Santhi Prakash017ebb091aa6
diff --git a/agent/storage_pool.go b/agent/storage_pool.goindex 0937117e8..7cf12dcb4 100644--- a/agent/storage_pool.go+++ b/agent/storage_pool.go@@ -391,6 +391,7 @@ func (b *poolBackend) collectDetail(previous *zfsentity.ZfsData) (*zfsentity.ZfsFree: p.Free,}if st, ok := statusByPool[p.Name]; statusErr == nil && ok {+ detail.Status = st.Statusif st.Scrub.State != "" && st.Scrub.State != "NONE" {detail.Scrub = &zfsentity.Scrub{State: st.Scrub.State,@@ -409,6 +410,7 @@ func (b *poolBackend) collectDetail(previous *zfsentity.ZfsData) (*zfsentity.Zfs}} else {if cached := previousByPool[p.Name]; cached != nil {+ detail.Status = cached.Statusdetail.Scrub = cached.Scrubdetail.Vdevs = cached.Vdevs}diff --git a/agent/storage_pool_test.go b/agent/storage_pool_test.goindex 5fe9f8e27..528034315 100644--- a/agent/storage_pool_test.go+++ b/agent/storage_pool_test.go@@ -386,13 +386,14 @@ func TestGetDetailFailureReturnsIncompleteCachedInventory(t *testing.T) {return []zfs.PoolStat{{Name: "tank"}}, nil}zm.backends[0].poolStatusesFn = func() ([]zfs.PoolStatus, error) {- return []zfs.PoolStatus{{Name: "tank", Vdevs: []zfs.VdevStatus{{Name: "mirror-0"}}}}, nil+ return []zfs.PoolStatus{{Name: "tank", Status: "test advisory", Vdevs: []zfs.VdevStatus{{Name: "mirror-0"}}}}, nil}zm.backends[0].datasetsFn = func() ([]zfs.Dataset, error) {return []zfs.Dataset{{Name: "tank/data"}}, nil}first := zm.GetDetail(false)require.True(t, first.Complete)+ assert.Equal(t, "test advisory", first.Pools[0].Status)require.Len(t, first.Pools[0].Vdevs, 1)require.Len(t, first.Pools[0].Datasets, 1)@@ -400,6 +401,7 @@ func TestGetDetailFailureReturnsIncompleteCachedInventory(t *testing.T) {zm.backends[0].datasetsFn = func() ([]zfs.Dataset, error) { return nil, zfs.ErrNoZfs }partial := zm.GetDetail(true)require.True(t, partial.Complete)+ assert.Equal(t, "test advisory", partial.Pools[0].Status)require.Len(t, partial.Pools[0].Vdevs, 1)require.Len(t, partial.Pools[0].Datasets, 1)diff --git a/agent/test-data/zfs/zpool_status.txt b/agent/test-data/zfs/zpool_status.txtindex e25076c84..b52ce344d 100644--- a/agent/test-data/zfs/zpool_status.txt+++ b/agent/test-data/zfs/zpool_status.txt@@ -27,3 +27,21 @@ config:sdb FAULTED 1 2 3errors: 1 data errors, use '-v' for a list++ pool: pve1storage+ state: ONLINE+status: One or more devices has experienced an unrecoverable error. An+ attempt was made to correct the error. Applications are unaffected.+action: Determine if the device needs to be replaced, and clear the errors+ using 'zpool clear' or replace the device with 'zpool replace'.+ see: https://openzfs.github.io/openzfs-docs/msg/ZFS-8000-9P+ scan: scrub repaired 208K in 15:18:53 with 0 errors on Thu Oct 1 15:40:36 2026+config:++ NAME STATE READ WRITE CKSUM+ pve1storage ONLINE 0 0 0+ raidz2-0 ONLINE 0 0 0+ sda ONLINE 0 0 0+ sdb ONLINE 0 0 1++errors: No known data errorsdiff --git a/agent/zfs/zfs_status.go b/agent/zfs/zfs_status.goindex 052d7e723..22050e406 100644--- a/agent/zfs/zfs_status.go+++ b/agent/zfs/zfs_status.go@@ -11,10 +11,11 @@ import (// PoolStatus holds parsed `zpool status` information for one pool.type PoolStatus struct {- Name string- State string // ONLINE, DEGRADED, FAULTED, ...- Scrub ScrubStatus- Vdevs []VdevStatus+ Name string+ State string // ONLINE, DEGRADED, FAULTED, ...+ Status string // status: advisory message, when the pool carries one+ Scrub ScrubStatus+ Vdevs []VdevStatus}// ScrubStatus holds the scrub (or resilver) status parsed from the scan line.@@ -54,6 +55,7 @@ func parseZpoolStatusOutput(out []byte) ([]PoolStatus, error) {var pools []PoolStatusvar current *PoolStatusinConfig := false+ inStatus := false // next indented line continues the status: messagescanContinuation := false // next non-blank line continues the scan line (progress)scanner := bufio.NewScanner(bytes.NewReader(out))@@ -66,17 +68,31 @@ func parseZpoolStatusOutput(out []byte) ([]PoolStatus, error) {pools = append(pools, PoolStatus{Name: strings.TrimSpace(strings.TrimPrefix(trimmed, "pool:"))})current = &pools[len(pools)-1]inConfig = false+ inStatus = falsescanContinuation = falsecase current == nil:continuecase strings.HasPrefix(trimmed, "state:"):current.State = strings.TrimSpace(strings.TrimPrefix(trimmed, "state:"))+ case strings.HasPrefix(trimmed, "status:"):+ current.Status = strings.Join(strings.Fields(strings.TrimPrefix(trimmed, "status:")), " ")+ inStatus = true+ case strings.HasPrefix(trimmed, "action:"), strings.HasPrefix(trimmed, "see:"):+ // action:/see: follow the status message; see: is itself indented.+ inStatus = falsecase strings.HasPrefix(trimmed, "scan:"):current.Scrub = parseScanLine(trimmed)// zpool status prints the progress percentage on the line after scan.scanContinuation = true+ inStatus = falsecase trimmed == "config:":inConfig = true+ inStatus = false+ case inStatus && trimmed != "" && (strings.HasPrefix(line, " ") || strings.HasPrefix(line, "\t")):+ // The status message wraps onto indented continuation lines.+ current.Status = strings.TrimSpace(current.Status + " " + strings.Join(strings.Fields(trimmed), " "))+ case inStatus:+ inStatus = falsecase scanContinuation:// The line after scan: may be an indented progress continuation.if m := progressRe.FindStringSubmatch(trimmed); m != nil {diff --git a/agent/zfs/zfs_test.go b/agent/zfs/zfs_test.goindex 0472434d9..db0fbd467 100644--- a/agent/zfs/zfs_test.go+++ b/agent/zfs/zfs_test.go@@ -73,11 +73,12 @@ func TestParseZpoolStatusOutput(t *testing.T) {pools, err := parseZpoolStatusOutput(data)require.NoError(t, err)- require.Len(t, pools, 2)+ require.Len(t, pools, 3)tank := pools[0]assert.Equal(t, "tank", tank.Name)assert.Equal(t, "ONLINE", tank.State)+ assert.Empty(t, tank.Status)assert.Equal(t, "FINISHED", tank.Scrub.State)assert.Equal(t, "", tank.Scrub.Progress)assert.Equal(t, uint64(0), tank.Scrub.Errors)@@ -90,6 +91,7 @@ func TestParseZpoolStatusOutput(t *testing.T) {rpool := pools[1]assert.Equal(t, "rpool", rpool.Name)assert.Equal(t, "DEGRADED", rpool.State)+ assert.Equal(t, "One or more devices could not be used because the label is missing or invalid. Sufficient replicas exist for the pool to continue functioning in a degraded state.", rpool.Status)assert.Equal(t, "SCANNING", rpool.Scrub.State)assert.Equal(t, "10.00%", rpool.Scrub.Progress)require.Len(t, rpool.Vdevs, 3)@@ -97,6 +99,17 @@ func TestParseZpoolStatusOutput(t *testing.T) {assert.Equal(t, uint64(1), rpool.Vdevs[2].ReadErrs)assert.Equal(t, uint64(2), rpool.Vdevs[2].WriteErrs)assert.Equal(t, uint64(3), rpool.Vdevs[2].ChecksumErrs)++ // state: ONLINE with a status: message (ZFS-8000-9P) - issue #2490.+ // The status text stops at action:/see: and the pool stays ONLINE.+ pve := pools[2]+ assert.Equal(t, "pve1storage", pve.Name)+ assert.Equal(t, "ONLINE", pve.State)+ assert.Equal(t, "One or more devices has experienced an unrecoverable error. An attempt was made to correct the error. Applications are unaffected.", pve.Status)+ assert.Equal(t, "FINISHED", pve.Scrub.State)+ require.Len(t, pve.Vdevs, 3)+ assert.Equal(t, "raidz2-0", pve.Vdevs[0].Name)+ assert.Equal(t, uint64(1), pve.Vdevs[2].ChecksumErrs)}func TestParseScanLine(t *testing.T) {diff --git a/internal/entities/zfs/zfs.go b/internal/entities/zfs/zfs.goindex 99aea84a8..a3d9adea5 100644--- a/internal/entities/zfs/zfs.go+++ b/internal/entities/zfs/zfs.go@@ -36,6 +36,7 @@ type PoolDetail struct {Raw bool `json:"raw,omitempty"`Name string `json:"name"`Health string `json:"health,omitempty"`+ Status string `json:"status,omitempty"`Size uint64 `json:"size,omitempty"` // bytesAlloc uint64 `json:"alloc,omitempty"` // bytesFree uint64 `json:"free,omitempty"` // bytesdiff --git a/internal/hub/systems/system_zfs.go b/internal/hub/systems/system_zfs.goindex 9d04d444e..9f6405290 100644--- a/internal/hub/systems/system_zfs.go+++ b/internal/hub/systems/system_zfs.go@@ -144,6 +144,7 @@ func (sys *System) upsertZfsPoolRecord(app core.App, collection *core.Collectionrecord.Set("name", pool.Name)record.Set("display_name", pool.DisplayName)record.Set("health", pool.Health)+ record.Set("status", pool.Status)record.Set("size", pool.Size)record.Set("alloc", pool.Alloc)record.Set("free", pool.Free)diff --git a/internal/hub/systems/system_zfs_test.go b/internal/hub/systems/system_zfs_test.goindex 07ffa0eee..3dbfc02a7 100644--- a/internal/hub/systems/system_zfs_test.go+++ b/internal/hub/systems/system_zfs_test.go@@ -99,11 +99,12 @@ func TestSaveZfsPoolsCompleteEmptyPrunesFinalPool(t *testing.T) {sys, app := newTestSystemWithHub(t)require.NoError(t, sys.saveZfsPools(&zfs.ZfsData{Complete: true,- Pools: []*zfs.PoolDetail{{Name: "tank", Health: "ONLINE"}},+ Pools: []*zfs.PoolDetail{{Name: "tank", Health: "ONLINE", Status: "One or more devices has experienced an unrecoverable error."}},}))records, err := app.FindRecordsByFilter("zfs_pools", "system={:system}", "", 0, 0, map[string]any{"system": sys.Id})require.NoError(t, err)require.Len(t, records, 1)+ assert.Equal(t, "One or more devices has experienced an unrecoverable error.", records[0].GetString("status"))assert.False(t, records[0].GetDateTime("details_updated").Time().IsZero())require.NoError(t, sys.saveZfsPools(&zfs.ZfsData{Complete: true}))diff --git a/internal/migrations/1790924727_zfs_pool_status.go b/internal/migrations/1790924727_zfs_pool_status.gonew file mode 100644index 000000000..ecdd48502--- /dev/null+++ b/internal/migrations/1790924727_zfs_pool_status.go@@ -0,0 +1,24 @@+package migrations++import (+ "github.com/pocketbase/pocketbase/core"+ m "github.com/pocketbase/pocketbase/migrations"+)++func init() {+ m.Register(func(app core.App) error {+ collection, err := app.FindCollectionByNameOrId("zfs_pools")+ if err != nil {+ return err+ }+ collection.Fields.Add(&core.TextField{Id: "zfs_pool_status", Name: "status"})+ return app.Save(collection)+ }, func(app core.App) error {+ collection, err := app.FindCollectionByNameOrId("zfs_pools")+ if err != nil {+ return err+ }+ collection.Fields.RemoveByName("status")+ return app.Save(collection)+ })+}diff --git a/internal/site/src/components/routes/system/storage-pools-table.tsx b/internal/site/src/components/routes/system/storage-pools-table.tsxindex 0cad1d092..06d5c596b 100644--- a/internal/site/src/components/routes/system/storage-pools-table.tsx+++ b/internal/site/src/components/routes/system/storage-pools-table.tsx@@ -42,13 +42,19 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"import { RawCapacityLabel } from "./raw-capacity-label"-const ZFS_POOL_FIELDS = "id,system,name,display_name,health,size,alloc,free,raw,scrub,details_updated,updated"+const ZFS_POOL_FIELDS = "id,system,name,display_name,health,size,alloc,free,raw,scrub,vdevs,details_updated,updated"-/** Maps a zpool health string to a Badge variant. */-function healthVariant(health: string): "success" | "warning" | "danger" | "outline" {+/** Reports whether any vdev has nonzero read, write, or checksum errors. */+function hasVdevErrors(vdevs?: ZfsVdev[] | null): boolean {+ return !!vdevs?.some((vdev) => vdev.readErrs || vdev.writeErrs || vdev.checksumErrs)+}++/** Maps a zpool health string to a Badge variant. An ONLINE pool with vdev+ * error counters (e.g. corrected checksum errors) is shown as a warning. */+function healthVariant(health: string, hasErrors = false): "success" | "warning" | "danger" | "outline" {switch (health) {case "ONLINE":- return "success"+ return hasErrors ? "warning" : "success"case "DEGRADED":return "warning"case "FAULTED":@@ -113,9 +119,9 @@ const columns: ColumnDef<ZfsPoolRecord>[] = [accessorKey: "health",sortingFn: (a, b) => a.original.health.localeCompare(b.original.health),header: ({ column }) => <HeaderButton column={column} name={t`Health`} Icon={ActivityIcon} />,- cell: ({ getValue }) => {+ cell: ({ getValue, row }) => {const health = (getValue() as string) || ""- return <Badge variant={healthVariant(health)}>{health || t`Unknown`}</Badge>+ return <Badge variant={healthVariant(health, hasVdevErrors(row.original.vdevs))}>{health || t`Unknown`}</Badge>},},{@@ -354,7 +360,7 @@ function PoolSheet({}, [open, poolId])const health = pool?.health || ""- const healthVariantValue = healthVariant(health)+ const healthVariantValue = healthVariant(health, hasVdevErrors(pool?.vdevs))const HealthIcon =healthVariantValue === "success"? CheckCircleIcon@@ -410,6 +416,7 @@ function PoolSheet({<AlertTitle><Trans>Pool Health</Trans>: {health}</AlertTitle>+ {pool.status && <AlertDescription>{pool.status}</AlertDescription>}{pool.scrub?.state && (<AlertDescription>Scrub: {pool.scrub.state}diff --git a/internal/site/src/types.d.ts b/internal/site/src/types.d.tsindex 38febbe6f..267bda042 100644--- a/internal/site/src/types.d.ts+++ b/internal/site/src/types.d.ts@@ -260,6 +260,8 @@ export interface ZfsPoolRecord extends RecordModel {system: stringname: stringhealth: string+ /** zpool status: advisory message, when the pool carries one */+ status?: stringsize: numberalloc: numberfree: number