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
Treat the ZFS ARC as reclaimable cache in TrueNAS memory
rcourtman5b86a19ebc4d
diff --git a/frontend-modern/src/features/truenas/TrueNASSystemsTable.tsx b/frontend-modern/src/features/truenas/TrueNASSystemsTable.tsxindex 8c6457ee87..ff9d00f74a 100644--- a/frontend-modern/src/features/truenas/TrueNASSystemsTable.tsx+++ b/frontend-modern/src/features/truenas/TrueNASSystemsTable.tsx@@ -324,6 +324,8 @@ export const TrueNASSystemsTable: Component<{const memoryTotal = () =>getPlatformTableFiniteMetric(system.memory?.total) ?? 0;const memoryUsed = () => getPlatformTableFiniteMetric(system.memory?.used) ?? 0;+ const memoryCache = () =>+ getPlatformTableFiniteMetric(system.agent?.memory?.cache) ?? 0;const memoryPercentOnly = () =>memoryTotal() > 0? undefined@@ -406,6 +408,8 @@ export const TrueNASSystemsTable: Component<{<StackedMemoryBarused={memoryUsed()}total={memoryTotal()}+ cache={memoryCache()}+ cacheInclusiveLabel="Used with ARC cache"percentOnly={memoryPercentOnly()}thresholds={memoryThresholds()}/>diff --git a/internal/truenas/client.go b/internal/truenas/client.goindex d101c23d73..49aebada7a 100644--- a/internal/truenas/client.go+++ b/internal/truenas/client.go@@ -1853,6 +1853,9 @@ func mergeSystemTelemetry(system *SystemInfo, telemetry *SystemInfo) {if telemetry.MemoryAvailableBytes > 0 {system.MemoryAvailableBytes = telemetry.MemoryAvailableBytes}+ if telemetry.ARCSizeBytes > 0 {+ system.ARCSizeBytes = telemetry.ARCSizeBytes+ }system.CPUPercent = telemetry.CPUPercentsystem.NetInRate = telemetry.NetInRatesystem.NetOutRate = telemetry.NetOutRate@@ -2613,6 +2616,7 @@ func (c *trueNASRPCClient) getSystemMetricHistory(ctx context.Context, durationresponse, err := c.getReportingDataWithQuery(ctx, []map[string]any{{"name": "cpu", "identifier": nil},{"name": "memory", "identifier": nil},+ {"name": "arcsize", "identifier": nil},{"name": "interface", "identifier": nil},{"name": "disk", "identifier": nil},}, map[string]any{@@ -2873,6 +2877,7 @@ func parseSystemTelemetry(fields map[string]any, intervalSeconds int, collectedAavailable := readInt64Any(memory, "physical_memory_available", "available", "free", "available_bytes", "free_bytes")telemetry.MemoryTotalBytes = totaltelemetry.MemoryAvailableBytes = available+ telemetry.ARCSizeBytes = readInt64Any(memory, "arc_size")interfaces := readMapAny(fields, "interfaces")for _, raw := range interfaces {@@ -2957,7 +2962,7 @@ func parseSystemMetricHistory(responses []trueNASReportingGetDataResponse) *Systfor _, response := range responses {name := strings.TrimSpace(strings.ToLower(response.Name))switch name {- case "cpu", "memory", "interface", "disk":+ case "cpu", "memory", "arcsize", "interface", "disk":default:continue}@@ -2986,6 +2991,10 @@ func parseSystemMetricHistory(responses []trueNASReportingGetDataResponse) *Systif value, ok := pickReportingValue(values, "total", "memory_total", "total_bytes", "physical_memory_total"); ok {history.MemoryTotalBytes = appendTimeSeriesPoint(history.MemoryTotalBytes, timestamp, value)}+ case "arcsize":+ if value, ok := pickReportingValue(values, "arc_size", "size", "arcsize"); ok {+ history.ARCSizeBytes = appendTimeSeriesPoint(history.ARCSizeBytes, timestamp, value)+ }case "interface":if value, ok := pickReportingValue(values, "received", "received_bytes", "rx", "rx_bytes", "netin", "in"); ok {history.NetInRate = appendTimeSeriesPoint(history.NetInRate, timestamp, value)@@ -3009,6 +3018,7 @@ func parseSystemMetricHistory(responses []trueNASReportingGetDataResponse) *Systlen(history.MemoryUsedBytes) == 0 &&len(history.MemoryAvailableBytes) == 0 &&len(history.MemoryTotalBytes) == 0 &&+ len(history.ARCSizeBytes) == 0 &&len(history.NetInRate) == 0 &&len(history.NetOutRate) == 0 &&len(history.DiskReadRate) == 0 &&diff --git a/internal/truenas/client_test.go b/internal/truenas/client_test.goindex a81816d328..5025682624 100644--- a/internal/truenas/client_test.go+++ b/internal/truenas/client_test.go@@ -1011,7 +1011,7 @@ func TestGetSystemMetricHistoryUsesReportingRPC(t *testing.T) {t.Fatalf("unexpected history params: %#v", historyReq.Params)}graphs, ok := params[0].([]any)- if !ok || len(graphs) != 4 {+ if !ok || len(graphs) != 5 {t.Fatalf("unexpected history graphs: %#v", params[0])}query, ok := params[1].(map[string]any)diff --git a/internal/truenas/issue1668_arc_memory_test.go b/internal/truenas/issue1668_arc_memory_test.gonew file mode 100644index 0000000000..a96b47c248--- /dev/null+++ b/internal/truenas/issue1668_arc_memory_test.go@@ -0,0 +1,114 @@+package truenas++import (+ "testing"+ "time"+)++// Issue #1668: TrueNAS reserves most RAM for the ZFS ARC, and the kernel's+// MemAvailable does not count ARC even though it shrinks under pressure, so+// memory derived from total-available read ~95% used on every ZFS system.+// ARC must be treated as reclaimable cache.++func TestParseSystemTelemetryReadsARCSize(t *testing.T) {+ telemetry := parseSystemTelemetry(map[string]any{+ "memory": map[string]any{+ "physical_memory_total": int64(68719476736),+ "physical_memory_available": int64(3435973836),+ "arc_size": int64(51539607552),+ },+ }, 2, time.Now())++ if telemetry.MemoryTotalBytes != 68719476736 {+ t.Fatalf("MemoryTotalBytes = %d", telemetry.MemoryTotalBytes)+ }+ if telemetry.ARCSizeBytes != 51539607552 {+ t.Fatalf("ARCSizeBytes = %d, want 51539607552", telemetry.ARCSizeBytes)+ }+}++func TestTrueNASEffectiveMemoryUsedExcludesARC(t *testing.T) {+ system := SystemInfo{+ MemoryTotalBytes: 64 << 30,+ MemoryAvailableBytes: 3 << 30,+ ARCSizeBytes: 48 << 30,+ }++ used := trueNASEffectiveMemoryUsed(system)+ want := int64(64<<30 - 3<<30 - 48<<30)+ if used != want {+ t.Fatalf("effective used = %d, want %d", used, want)+ }+ if cache := trueNASReclaimableARC(system); cache != 48<<30 {+ t.Fatalf("reclaimable ARC = %d, want %d", cache, int64(48<<30))+ }++ // used + cache + free must not exceed total.+ if used+trueNASReclaimableARC(system)+system.MemoryAvailableBytes > system.MemoryTotalBytes {+ t.Fatal("used + cache + free exceeds total")+ }+}++func TestTrueNASEffectiveMemoryUsedWithoutARCUnchanged(t *testing.T) {+ system := SystemInfo{+ MemoryTotalBytes: 64 << 30,+ MemoryAvailableBytes: 32 << 30,+ }+ if used := trueNASEffectiveMemoryUsed(system); used != 32<<30 {+ t.Fatalf("effective used without ARC = %d, want %d", used, int64(32<<30))+ }+ if cache := trueNASReclaimableARC(system); cache != 0 {+ t.Fatalf("reclaimable ARC without arc_size = %d, want 0", cache)+ }+}++func TestTrueNASReclaimableARCClampedToHeadroom(t *testing.T) {+ // An inconsistent snapshot (ARC larger than total-available) must not+ // drive used negative or let used+cache+free exceed total.+ system := SystemInfo{+ MemoryTotalBytes: 64 << 30,+ MemoryAvailableBytes: 60 << 30,+ ARCSizeBytes: 48 << 30,+ }+ if cache := trueNASReclaimableARC(system); cache != 4<<30 {+ t.Fatalf("clamped ARC = %d, want %d", cache, int64(4<<30))+ }+ if used := trueNASEffectiveMemoryUsed(system); used != 0 {+ t.Fatalf("effective used = %d, want 0", used)+ }+}++func TestSystemMemoryPercentHistorySubtractsARC(t *testing.T) {+ ts1 := time.Date(2026, 8, 2, 12, 0, 0, 0, time.UTC)+ ts2 := ts1.Add(time.Hour)+ history := &SystemMetricHistory{+ MemoryUsedBytes: []TimeSeriesPoint{+ {Timestamp: ts1, Value: 60 << 30},+ {Timestamp: ts2, Value: 62 << 30},+ },+ ARCSizeBytes: []TimeSeriesPoint{+ {Timestamp: ts1, Value: 48 << 30},+ {Timestamp: ts2, Value: 50 << 30},+ },+ }++ points := systemMemoryPercentHistory(history, 64<<30)+ if len(points) != 2 {+ t.Fatalf("expected 2 points, got %d", len(points))+ }+ wantFirst := (float64(60<<30) - float64(48<<30)) / float64(64<<30) * 100+ if diff := points[0].Value - wantFirst; diff > 0.01 || diff < -0.01 {+ t.Fatalf("first point = %.2f, want %.2f", points[0].Value, wantFirst)+ }+}++func TestSystemMemoryPercentHistoryWithoutARCUnchanged(t *testing.T) {+ ts := time.Date(2026, 8, 2, 12, 0, 0, 0, time.UTC)+ history := &SystemMetricHistory{+ MemoryUsedBytes: []TimeSeriesPoint{{Timestamp: ts, Value: 32 << 30}},+ }+ points := systemMemoryPercentHistory(history, 64<<30)+ if len(points) != 1 || points[0].Value != 50 {+ t.Fatalf("expected unchanged 50%%, got %+v", points)+ }+}diff --git a/internal/truenas/provider.go b/internal/truenas/provider.goindex 157426b070..dd13930a7b 100644--- a/internal/truenas/provider.go+++ b/internal/truenas/provider.go@@ -897,6 +897,36 @@ func metricsFromTrueNASApp(app App, hostMemoryTotalBytes int64) *unifiedresourcereturn metrics}+// trueNASReclaimableARC returns the ZFS ARC size clamped so that+// used + cache + free never exceeds total.+func trueNASReclaimableARC(system SystemInfo) int64 {+ arc := system.ARCSizeBytes+ if arc <= 0 {+ return 0+ }+ headroom := system.MemoryTotalBytes - system.MemoryAvailableBytes+ if headroom < 0 {+ headroom = 0+ }+ if arc > headroom {+ arc = headroom+ }+ return arc+}++// trueNASEffectiveMemoryUsed treats the ZFS ARC as reclaimable cache, the+// same way node memory accounting treats buffers and page cache: the+// kernel's MemAvailable does not count ARC even though it shrinks under+// pressure, so raw total-available reads ~95% used on every ZFS system+// (#1668).+func trueNASEffectiveMemoryUsed(system SystemInfo) int64 {+ used := system.MemoryTotalBytes - system.MemoryAvailableBytes - trueNASReclaimableARC(system)+ if used < 0 {+ used = 0+ }+ return used+}+func metricsFromTrueNASSystem(system SystemInfo, totalCapacity, totalUsed int64) *unifiedresources.ResourceMetrics {hasRealtimeTelemetry := !system.CollectedAt.IsZero() || system.IntervalSeconds > 0metrics := &unifiedresources.ResourceMetrics{@@ -913,10 +943,7 @@ func metricsFromTrueNASSystem(system SystemInfo, totalCapacity, totalUsed int64)}if system.MemoryTotalBytes > 0 {- used := system.MemoryTotalBytes - system.MemoryAvailableBytes- if used < 0 {- used = 0- }+ used := trueNASEffectiveMemoryUsed(system)memory := &unifiedresources.MetricValue{Used: &used,Total: &system.MemoryTotalBytes,@@ -981,10 +1008,7 @@ func agentDataFromTrueNASSystem(connectionID string, system SystemInfo, disks []}if system.MemoryTotalBytes > 0 {- used := system.MemoryTotalBytes - system.MemoryAvailableBytes- if used < 0 {- used = 0- }+ used := trueNASEffectiveMemoryUsed(system)free := system.MemoryAvailableBytesif free < 0 {free = 0@@ -993,6 +1017,7 @@ func agentDataFromTrueNASSystem(connectionID string, system SystemInfo, disks []Total: system.MemoryTotalBytes,Used: used,Free: free,+ Cache: trueNASReclaimableARC(system),}}if temperature := maxTrueNASSystemTemperature(system); temperature != nil {@@ -2679,7 +2704,14 @@ func systemMemoryPercentHistory(history *SystemMetricHistory, fallbackTotalBytesif history == nil {return nil}- if len(history.MemoryPercent) > 0 {++ // The netdata memory series counts the ZFS ARC as used, which reads ~95%+ // on every ZFS system. Subtract the ARC series per point so history+ // matches the ARC-aware current value (#1668). Without ARC data the raw+ // series passes through unchanged.+ arcAt := arcSizeLookup(history.ARCSizeBytes)++ if len(history.MemoryPercent) > 0 && len(arcAt) == 0 {return cloneTimeSeriesPoints(history.MemoryPercent)}@@ -2690,15 +2722,26 @@ func systemMemoryPercentHistory(history *SystemMetricHistory, fallbackTotalBytes}}if totalBytes <= 0 {+ if len(history.MemoryPercent) > 0 {+ return cloneTimeSeriesPoints(history.MemoryPercent)+ }return nil}+ clampPercent := func(value float64) float64 {+ if value < 0 {+ return 0+ }+ return value+ }+if len(history.MemoryUsedBytes) > 0 {points := make([]TimeSeriesPoint, 0, len(history.MemoryUsedBytes))for _, point := range history.MemoryUsedBytes {+ used := point.Value - arcAt[point.Timestamp.Unix()]points = append(points, TimeSeriesPoint{Timestamp: point.Timestamp,- Value: (point.Value / totalBytes) * 100,+ Value: clampPercent((used / totalBytes) * 100),})}return points@@ -2706,16 +2749,33 @@ func systemMemoryPercentHistory(history *SystemMetricHistory, fallbackTotalBytesif len(history.MemoryAvailableBytes) > 0 {points := make([]TimeSeriesPoint, 0, len(history.MemoryAvailableBytes))for _, point := range history.MemoryAvailableBytes {+ used := totalBytes - point.Value - arcAt[point.Timestamp.Unix()]points = append(points, TimeSeriesPoint{Timestamp: point.Timestamp,- Value: ((totalBytes - point.Value) / totalBytes) * 100,+ Value: clampPercent((used / totalBytes) * 100),})}return points}+ if len(history.MemoryPercent) > 0 {+ return cloneTimeSeriesPoints(history.MemoryPercent)+ }return nil}+// arcSizeLookup indexes an ARC size series by unix timestamp. Missing+// timestamps read as zero, leaving those points unadjusted.+func arcSizeLookup(series []TimeSeriesPoint) map[int64]float64 {+ if len(series) == 0 {+ return nil+ }+ lookup := make(map[int64]float64, len(series))+ for _, point := range series {+ lookup[point.Timestamp.Unix()] = point.Value+ }+ return lookup+}+// trueNASSystemMetricResourceID must stay systemSourceID minus its "system:"// prefix: BuildMetricsTarget derives the agent metric target by stripping// that prefix from the TrueNAS source ID (canonicalAgentMetricID), and thediff --git a/internal/truenas/types.go b/internal/truenas/types.goindex 70900189cb..ea2e9dd990 100644--- a/internal/truenas/types.go+++ b/internal/truenas/types.go@@ -29,14 +29,18 @@ type SystemInfo struct {CPUCount intMemoryTotalBytes int64MemoryAvailableBytes int64- CPUPercent float64- NetInRate float64- NetOutRate float64- DiskReadRate float64- DiskWriteRate float64- TemperatureCelsius map[string]float64- IntervalSeconds int- CollectedAt time.Time+ // ARCSizeBytes is the ZFS ARC cache size. The kernel's MemAvailable does+ // not count ARC even though it shrinks under memory pressure, so usage+ // derived from total-available alone reads ~95% on every ZFS system.+ ARCSizeBytes int64+ CPUPercent float64+ NetInRate float64+ NetOutRate float64+ DiskReadRate float64+ DiskWriteRate float64+ TemperatureCelsius map[string]float64+ IntervalSeconds int+ CollectedAt time.Time}// Pool mirrors the subset of TrueNAS pool fields needed for unified mapping.@@ -187,6 +191,7 @@ type SystemMetricHistory struct {MemoryUsedBytes []TimeSeriesPointMemoryAvailableBytes []TimeSeriesPointMemoryTotalBytes []TimeSeriesPoint+ ARCSizeBytes []TimeSeriesPointNetInRate []TimeSeriesPointNetOutRate []TimeSeriesPointDiskReadRate []TimeSeriesPoint