The safety review of the first version found it safe for the pool's data and asked for these fixes before it goes on the home server: - zfs_snapshot: no recursive. Every answer gives the dataset's free space and the pool's capacity, and says that the snapshot holds every block deleted or overwritten until it is destroyed by hand. - A command that runs out of time is ended with its whole process group. An act that timed out is answered from the list, or as "outcome unknown", never as "NOT DONE". - The watch runs as the operator account. - The event follower reads ZFS's queue from its start, with a cursor per boot, so the pool's import and any downtime reach the journal once. It writes "dropped N events", kills zpool before waiting for it, and exits non-zero after five failed follows in a row. - Past error counts are a warning, and counts that rise are unhealthy. - The guard test catches .Run(, exec.Command(, exec.CommandContext( and process starts. - The fixtures and the parser follow OpenZFS 2.4.4's own printers: human scan sizes under -p, no iostat section lines, error scrubs, per-vdev rebuild resilvers, paused scrubs. The operator also asked the module to own the scrub. A timer and a service of the module's own run zpool scrub -w -- <pool> from the scrub-pool, scrub-cadence, scrub-day and scrub-time settings. In the same declaration, the distribution's weekly and monthly timers for that pool are held stopped and disabled, so exactly one schedule scrubs it. zfs_scrub shows the schedule and the next run, with any resilver's progress. zfs_scrub_start, zfs_scrub_pause and zfs_scrub_stop act with why. The health check warns of a late or failed scrub and of a running resilver, and is unhealthy for a resilver that finished with errors.
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"time"
|
|
)
|
|
|
|
// WatchEvery is how often the watch looks at the pools.
|
|
const WatchEvery = time.Minute
|
|
|
|
// The module's one long-running process (`zfs-tools watch`), run by the node-engine. It is what the
|
|
// module's health is declared on (novox/hq ADR 0240: a tool check stands on a long-running resource): the
|
|
// node-engine judges the process alive, and asks zfs_health whether the pools are. The watch itself
|
|
// writes no file and changes nothing: each minute it reads the pools, and says in its journal when their
|
|
// health changes, so the journal holds when a pool went DEGRADED and when it came back.
|
|
|
|
// Watch keeps the last verdict, to say only changes.
|
|
type Watch struct {
|
|
M *Machine
|
|
Out io.Writer
|
|
last string
|
|
}
|
|
|
|
// Look reads the pools once and says the verdict when it changed.
|
|
func (w *Watch) Look(ctx context.Context) {
|
|
h := w.M.Health(ctx)
|
|
verdict := "healthy"
|
|
if !h.Healthy {
|
|
verdict = "UNHEALTHY"
|
|
}
|
|
line := verdict + ": " + h.Why
|
|
if line != w.last {
|
|
fmt.Fprintf(w.Out, "%s %s\n", w.M.Now().Format(time.RFC3339), line)
|
|
w.last = line
|
|
}
|
|
}
|
|
|
|
// Loop looks every WatchEvery until the context ends.
|
|
func (w *Watch) Loop(ctx context.Context) {
|
|
w.Look(ctx)
|
|
t := time.NewTicker(WatchEvery)
|
|
defer t.Stop()
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-t.C:
|
|
w.Look(ctx)
|
|
}
|
|
}
|
|
}
|