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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
feat(truenas): sync api-backed disk history
rcourtmanaab6b5e69d07
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 7aae46b6b5..c909053683 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -231,6 +231,12 @@ That same monitoring boundary now also owns live TrueNAS disk temperatures.`disk.temperatures` from the TrueNAS API and project those readings into thecanonical physical-disk model and risk path instead of leaving temperaturetelemetry agent-only or adding a TrueNAS-local presentation shim.+That same boundary now also owns the canonical disk-history write path for+API-backed disks. `internal/monitoring/monitor.go` must sync non-native+physical-disk resources such as TrueNAS disks into the shared `disk`+metrics-store contract via the existing SMART-temperature writer, so physical+disk charts and disk-health consumers read one history path instead of a+TrueNAS-only temperature cache.That same monitoring boundary now also owns modern TrueNAS app workloadtelemetry. `internal/truenas/client.go`, `internal/truenas/provider.go`, and`internal/monitoring/monitor.go` must ingest `app.stats` through the officialdiff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex 8c2e753149..aecb5b023f 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -836,6 +836,10 @@ Canonical physical-disk views now expose the full disk identity and SMARTmetadata needed by monitoring refresh paths, so physical-disk temperature andSMART merges can run from unified `ReadState` instead of from snapshot-owneddisk arrays.+That same canonical physical-disk view must also expose source-independent host+context. When a disk is API-backed rather than node-backed, typed views should+fall back to canonical host identity such as `identity.hostnames` instead of+returning an empty node label purely because no Proxmox metadata is present.Canonical identity now also treats Proxmox-backed infrastructure parents asnode-owned resources first: when an agent resource carries canonical Proxmoxdiff --git a/internal/monitoring/canonical_guardrails_test.go b/internal/monitoring/canonical_guardrails_test.goindex e4d75db13b..98f06944c8 100644--- a/internal/monitoring/canonical_guardrails_test.go+++ b/internal/monitoring/canonical_guardrails_test.go@@ -188,6 +188,25 @@ func TestUnifiedAgentMetricsUseCanonicalHostHistoryPath(t *testing.T) {}}+func TestUnifiedPhysicalDiskMetricsUseCanonicalDiskHistoryPath(t *testing.T) {+ data, err := os.ReadFile("monitor.go")+ if err != nil {+ t.Fatalf("failed to read monitor.go: %v", err)+ }+ source := string(data)+ requiredSnippets := []string{+ "m.syncUnifiedPhysicalDiskMetrics(store)",+ `if target == nil || target.ResourceType != "disk" || strings.TrimSpace(target.ResourceID) == "" {`,+ `if source == unifiedresources.SourceProxmox || source == unifiedresources.SourceAgent {`,+ `m.writeSMARTMetrics(disk, now)`,+ }+ for _, snippet := range requiredSnippets {+ if !strings.Contains(source, snippet) {+ t.Fatalf("monitor.go must contain %q", snippet)+ }+ }+}+func TestHostAgentRemovalGuardUsesResolvedIdentifier(t *testing.T) {data, err := os.ReadFile("monitor_agents.go")if err != nil {diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.goindex 951ccaa0d7..514ce80091 100644--- a/internal/monitoring/monitor.go+++ b/internal/monitoring/monitor.go@@ -4138,6 +4138,7 @@ func (m *Monitor) updateResourceStore(state models.StateSnapshot) {atomicStore.PopulateSnapshotAndSupplemental(snapshotForStore, recordsBySource)m.syncUnifiedAgentMetrics(store)m.syncUnifiedStorageMetrics(store)+ m.syncUnifiedPhysicalDiskMetrics(store)m.syncUnifiedAppContainerMetrics(store)for source, records := range recordsBySource {if len(records) == 0 {@@ -4170,6 +4171,7 @@ func (m *Monitor) updateResourceStore(state models.StateSnapshot) {m.syncUnifiedAgentMetrics(store)m.syncUnifiedStorageMetrics(store)+ m.syncUnifiedPhysicalDiskMetrics(store)m.syncUnifiedAppContainerMetrics(store)m.syncUnifiedResourceAlertsToState(store.GetAll())}@@ -4356,6 +4358,79 @@ func (m *Monitor) syncUnifiedStorageMetrics(store ResourceStoreInterface) {}}+func (m *Monitor) syncUnifiedPhysicalDiskMetrics(store ResourceStoreInterface) {+ if store == nil || m.metricsStore == nil {+ return+ }++ resolver, ok := store.(MetricsTargetResourceStore)+ if !ok {+ return+ }++ now := time.Now()+ seenTargets := make(map[string]struct{})+ for _, resource := range store.GetAll() {+ if resource.Type != unifiedresources.ResourceTypePhysicalDisk || resource.PhysicalDisk == nil {+ continue+ }++ hasNativeWriter := false+ for _, source := range resource.Sources {+ if source == unifiedresources.SourceProxmox || source == unifiedresources.SourceAgent {+ hasNativeWriter = true+ break+ }+ }+ if hasNativeWriter {+ continue+ }++ target := resolver.MetricsTargetForResource(resource.ID)+ if target == nil || target.ResourceType != "disk" || strings.TrimSpace(target.ResourceID) == "" {+ continue+ }+ targetID := strings.TrimSpace(target.ResourceID)+ if _, ok := seenTargets[targetID]; ok {+ continue+ }+ seenTargets[targetID] = struct{}{}++ nodeName := ""+ for _, hostname := range resource.Identity.Hostnames {+ if hostname = strings.TrimSpace(hostname); hostname != "" {+ nodeName = hostname+ break+ }+ }+ if nodeName == "" {+ nodeName = firstNonEmptyString(strings.TrimSpace(resource.ParentName), strings.TrimSpace(resource.Name))+ }++ disk := models.PhysicalDisk{+ ID: resource.ID,+ Node: nodeName,+ DevPath: resource.PhysicalDisk.DevPath,+ Model: resource.PhysicalDisk.Model,+ Serial: resource.PhysicalDisk.Serial,+ WWN: resource.PhysicalDisk.WWN,+ Type: resource.PhysicalDisk.DiskType,+ Size: resource.PhysicalDisk.SizeBytes,+ Health: resource.PhysicalDisk.Health,+ Wearout: resource.PhysicalDisk.Wearout,+ Temperature: resource.PhysicalDisk.Temperature,+ RPM: resource.PhysicalDisk.RPM,+ Used: resource.PhysicalDisk.Used,+ SmartAttributes: smartAttributesFromUnifiedMeta(resource.PhysicalDisk.SMART),+ LastChecked: resource.LastSeen,+ }+ if disk.Serial == "" {+ disk.ID = targetID+ }+ m.writeSMARTMetrics(disk, now)+ }+}+func (m *Monitor) syncUnifiedAppContainerMetrics(store ResourceStoreInterface) {if store == nil || (m.metricsHistory == nil && m.metricsStore == nil) {returndiff --git a/internal/monitoring/monitor_polling_test.go b/internal/monitoring/monitor_polling_test.goindex 89e1e69730..578e1b205f 100644--- a/internal/monitoring/monitor_polling_test.go+++ b/internal/monitoring/monitor_polling_test.go@@ -598,6 +598,69 @@ func TestSyncUnifiedAgentMetricsRecordsTrueNASHostHistory(t *testing.T) {}}+func TestSyncUnifiedPhysicalDiskMetricsRecordsTrueNASDiskHistory(t *testing.T) {+ previous := truenas.IsFeatureEnabled()+ truenas.SetFeatureEnabled(true)+ t.Cleanup(func() {+ truenas.SetFeatureEnabled(previous)+ })++ cfg := metrics.DefaultConfig(t.TempDir())+ store, err := metrics.NewStore(cfg)+ if err != nil {+ t.Fatalf("metrics.NewStore() error = %v", err)+ }+ defer func() { _ = store.Close() }()++ resourceStore := unifiedresources.NewMonitorAdapter(nil)+ records := truenas.NewProvider(truenas.DefaultFixtures()).Records()+ resourceStore.PopulateSnapshotAndSupplemental(models.StateSnapshot{}, map[unifiedresources.DataSource][]unifiedresources.IngestRecord{+ unifiedresources.SourceTrueNAS: records,+ })++ monitor := &Monitor{+ resourceStore: resourceStore,+ metricsStore: store,+ }++ monitor.syncUnifiedPhysicalDiskMetrics(resourceStore)++ var diskResourceID string+ for _, resource := range resourceStore.GetAll() {+ if resource.Type != unifiedresources.ResourceTypePhysicalDisk || resource.PhysicalDisk == nil {+ continue+ }+ if strings.TrimSpace(resource.PhysicalDisk.DevPath) == "/dev/sdc" {+ diskResourceID = resource.ID+ break+ }+ }+ if diskResourceID == "" {+ t.Fatal("expected TrueNAS sdc disk resource in unified store")+ }++ target := resourceStore.MetricsTargetForResource(diskResourceID)+ if target == nil || target.ResourceType != "disk" || target.ResourceID != "WD-WX12A3456" {+ t.Fatalf("unexpected physical-disk metrics target %+v", target)+ }++ charts := monitor.GetPhysicalDiskTemperatureCharts(7 * 24 * time.Hour)+ entry, ok := charts[target.ResourceID]+ if !ok {+ t.Fatalf("expected persisted disk chart for %s, got %#v", target.ResourceID, charts)+ }+ if entry.Node != "truenas-main" {+ t.Fatalf("chart node = %q, want truenas-main", entry.Node)+ }+ if len(entry.Temperature) == 0 {+ t.Fatalf("expected temperature history for %s", target.ResourceID)+ }+ last := entry.Temperature[len(entry.Temperature)-1]+ if last.Value != 63 {+ t.Fatalf("expected last disk temperature 63, got %.2f", last.Value)+ }+}+func TestBuildBroadcastFrontendStatePrefersLiveAlertManagerOverSnapshotAlerts(t *testing.T) {alertManager := alerts.NewManagerWithDataDir(t.TempDir())defer alertManager.Stop()diff --git a/internal/unifiedresources/views.go b/internal/unifiedresources/views.goindex 37f57cb0aa..d0cf36070e 100644--- a/internal/unifiedresources/views.go+++ b/internal/unifiedresources/views.go@@ -1899,10 +1899,18 @@ func (v PhysicalDiskView) Wearout() int {}func (v PhysicalDiskView) Node() string {- if v.r == nil || v.r.Proxmox == nil {+ if v.r == nil {return ""}- return v.r.Proxmox.NodeName+ if v.r.Proxmox != nil && strings.TrimSpace(v.r.Proxmox.NodeName) != "" {+ return strings.TrimSpace(v.r.Proxmox.NodeName)+ }+ for _, hostname := range v.r.Identity.Hostnames {+ if hostname = strings.TrimSpace(hostname); hostname != "" {+ return hostname+ }+ }+ return ""}func (v PhysicalDiskView) Instance() string {diff --git a/internal/unifiedresources/views_test.go b/internal/unifiedresources/views_test.goindex aa73acb696..5a5cde0a2b 100644--- a/internal/unifiedresources/views_test.go+++ b/internal/unifiedresources/views_test.go@@ -776,6 +776,30 @@ func TestView_PhysicalDiskViewAccessors(t *testing.T) {}}+func TestView_PhysicalDiskViewNodeFallsBackToIdentityHostnames(t *testing.T) {+ r := &Resource{+ ID: "disk-truenas-1",+ Type: ResourceTypePhysicalDisk,+ Status: StatusOnline,+ Identity: ResourceIdentity{+ Hostnames: []string{"", " truenas-main ", "truenas-backup"},+ },+ PhysicalDisk: &PhysicalDiskMeta{+ DevPath: "/dev/sdc",+ Model: "WD Red Plus",+ },+ }++ v := NewPhysicalDiskView(r)++ if got := v.Node(); got != "truenas-main" {+ t.Fatalf("expected Node() to fall back to canonical identity hostname %q, got %q", "truenas-main", got)+ }+ if got := v.Instance(); got != "" {+ t.Fatalf("expected Instance() to remain empty without Proxmox metadata, got %q", got)+ }+}+func TestView_DockerHostViewAccessors(t *testing.T) {now := time.Date(2026, 2, 10, 12, 4, 0, 0, time.UTC)temp := 44.4