sysinfo/internal/sysinfo/collector_zfs.go
2025-05-01 03:25:38 -07:00

38 lines
920 B
Go

package sysinfo
import (
"encoding/json"
"strings"
"time"
)
type ZFSCollector struct{}
func (ZFSCollector) SectionKey() string { return "zfs" }
func (ZFSCollector) EnsurePrerequisites(pm PackageManager, _ *Context) error {
if pm.Distro() == "ubuntu" {
return pm.InstallPackages("zfsutils-linux")
}
return nil
}
func (ZFSCollector) IsSupported(pm PackageManager, _ *Context) bool {
return pm.ExecExists("zpool")
}
func (ZFSCollector) CollectData(c *Context) (json.RawMessage, error) {
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)
}