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.

feat(agent): add FreeBSD S.M.A.R.T. disk collection support (#1236)

rcourtman47adcbd8af09
diff --git a/internal/hostagent/agent.go b/internal/hostagent/agent.go
index 838735e6ef..ab4eab0836 100644
--- a/internal/hostagent/agent.go
+++ b/internal/hostagent/agent.go
@@ -740,8 +740,8 @@ func (a *Agent) collectCephStatus(ctx context.Context) *agentshost.CephCluster {
// collectSMARTData collects S.M.A.R.T. data from local disks.
// Returns nil if smartctl is not available or no disks are found.
func (a *Agent) collectSMARTData(ctx context.Context) []agentshost.DiskSMART {
- // Only collect on Linux (smartctl works on other platforms but disk paths differ)
- if a.collector.GOOS() != "linux" {
+ goos := a.collector.GOOS()
+ if goos != "linux" && goos != "freebsd" {
return nil
}
diff --git a/internal/smartctl/collector.go b/internal/smartctl/collector.go
index d51f3e8204..bee97252ce 100644
--- a/internal/smartctl/collector.go
+++ b/internal/smartctl/collector.go
@@ -6,6 +6,7 @@ import (
"encoding/json"
"os/exec"
"path/filepath"
+ "runtime"
"strconv"
"strings"
"time"
@@ -18,7 +19,8 @@ var (
runCommandOutput = func(ctx context.Context, name string, args ...string) ([]byte, error) {
return exec.CommandContext(ctx, name, args...).Output()
}
- timeNow = time.Now
+ timeNow = time.Now
+ runtimeGOOS = runtime.GOOS
)
// DiskSMART represents S.M.A.R.T. data for a single disk.
@@ -135,7 +137,14 @@ func CollectLocal(ctx context.Context, diskExclude []string) ([]DiskSMART, error
// listBlockDevices returns a list of block devices suitable for SMART queries.
// Devices matching any of the diskExclude patterns are skipped.
func listBlockDevices(ctx context.Context, diskExclude []string) ([]string, error) {
- // Use lsblk to find disks (not partitions)
+ if runtimeGOOS == "freebsd" {
+ return listBlockDevicesFreeBSD(ctx, diskExclude)
+ }
+ return listBlockDevicesLinux(ctx, diskExclude)
+}
+
+// listBlockDevicesLinux uses lsblk to find disks on Linux.
+func listBlockDevicesLinux(ctx context.Context, diskExclude []string) ([]string, error) {
output, err := runCommandOutput(ctx, "lsblk", "-d", "-n", "-o", "NAME,TYPE")
if err != nil {
return nil, err
@@ -151,7 +160,6 @@ func listBlockDevices(ctx context.Context, diskExclude []string) ([]string, erro
// Only include disk types (not loop, rom, partition)
if devType == "disk" {
devicePath := "/dev/" + name
- // Check exclusion patterns
if matchesDeviceExclude(name, devicePath, diskExclude) {
log.Debug().Str("device", devicePath).Msg("Skipping excluded device for SMART collection")
continue
@@ -163,6 +171,29 @@ func listBlockDevices(ctx context.Context, diskExclude []string) ([]string, erro
return devices, nil
}
+// listBlockDevicesFreeBSD uses sysctl kern.disks to find disks on FreeBSD.
+func listBlockDevicesFreeBSD(ctx context.Context, diskExclude []string) ([]string, error) {
+ output, err := runCommandOutput(ctx, "sysctl", "-n", "kern.disks")
+ if err != nil {
+ return nil, err
+ }
+
+ var devices []string
+ for _, name := range strings.Fields(strings.TrimSpace(string(output))) {
+ if name == "" {
+ continue
+ }
+ devicePath := "/dev/" + name
+ if matchesDeviceExclude(name, devicePath, diskExclude) {
+ log.Debug().Str("device", devicePath).Msg("Skipping excluded device for SMART collection")
+ continue
+ }
+ devices = append(devices, devicePath)
+ }
+
+ return devices, nil
+}
+
// matchesDeviceExclude checks if a block device matches any exclusion pattern.
// Patterns can match against the device name (e.g., "sda", "nvme0n1") or the full
// path (e.g., "/dev/sda"). Supports:
diff --git a/internal/smartctl/collector_coverage_test.go b/internal/smartctl/collector_coverage_test.go
index 2aa89c14bc..bad30851f8 100644
--- a/internal/smartctl/collector_coverage_test.go
+++ b/internal/smartctl/collector_coverage_test.go
@@ -12,8 +12,10 @@ import (
func TestListBlockDevices(t *testing.T) {
origRun := runCommandOutput
- t.Cleanup(func() { runCommandOutput = origRun })
+ origGOOS := runtimeGOOS
+ t.Cleanup(func() { runCommandOutput = origRun; runtimeGOOS = origGOOS })
+ runtimeGOOS = "linux"
runCommandOutput = func(ctx context.Context, name string, args ...string) ([]byte, error) {
if name != "lsblk" {
return nil, errors.New("unexpected command")
@@ -31,6 +33,47 @@ func TestListBlockDevices(t *testing.T) {
}
}
+func TestListBlockDevicesFreeBSD(t *testing.T) {
+ origRun := runCommandOutput
+ origGOOS := runtimeGOOS
+ t.Cleanup(func() { runCommandOutput = origRun; runtimeGOOS = origGOOS })
+
+ runtimeGOOS = "freebsd"
+ runCommandOutput = func(ctx context.Context, name string, args ...string) ([]byte, error) {
+ if name != "sysctl" {
+ return nil, errors.New("unexpected command: " + name)
+ }
+ return []byte("ada0 da0 nvd0\n"), nil
+ }
+
+ devices, err := listBlockDevices(context.Background(), nil)
+ if err != nil {
+ t.Fatalf("listBlockDevices error: %v", err)
+ }
+ if len(devices) != 3 || devices[0] != "/dev/ada0" || devices[1] != "/dev/da0" || devices[2] != "/dev/nvd0" {
+ t.Fatalf("unexpected devices: %#v", devices)
+ }
+}
+
+func TestListBlockDevicesFreeBSDWithExcludes(t *testing.T) {
+ origRun := runCommandOutput
+ origGOOS := runtimeGOOS
+ t.Cleanup(func() { runCommandOutput = origRun; runtimeGOOS = origGOOS })
+
+ runtimeGOOS = "freebsd"
+ runCommandOutput = func(ctx context.Context, name string, args ...string) ([]byte, error) {
+ return []byte("ada0 da0 nvd0\n"), nil
+ }
+
+ devices, err := listBlockDevices(context.Background(), []string{"da0"})
+ if err != nil {
+ t.Fatalf("listBlockDevices error: %v", err)
+ }
+ if len(devices) != 2 || devices[0] != "/dev/ada0" || devices[1] != "/dev/nvd0" {
+ t.Fatalf("unexpected devices: %#v", devices)
+ }
+}
+
func TestListBlockDevicesError(t *testing.T) {
origRun := runCommandOutput
t.Cleanup(func() { runCommandOutput = origRun })