sysinfo/internal/sysinfo/collector_zfs.go
2025-05-01 03:11:54 -07:00

29 lines
714 B
Go

package sysinfo
import (
"encoding/json"
"strings"
)
type ZFSCollector struct{}
func (ZFSCollector) Key() string { return "zfs" }
func (ZFSCollector) Collect(c *Context) (json.RawMessage, error) {
if c.SafeRun("which", "zpool") == "" {
return json.Marshal(nil) // no zfs installed
}
pools := strings.Fields(
c.SafeRun("zpool", "list", "-H", "-o", "name"))
section := map[string]any{}
for _, p := range pools {
section[p] = map[string]string{
"timestamp": c.Now.Format(time.RFC3339),
"status": c.SafeRun("zpool", "status", "-v", p),
"get": c.SafeRun("zpool", "get", "-H", "all", p),
"zfs_list": c.SafeRun("zfs", "list", "-Hp", "-r", p),
}
}
return json.Marshal(section)
}