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(proxmox): show all LXC filesystems

[email protected]9b6df327ad00
diff --git a/docs/AGENT_SECURITY.md b/docs/AGENT_SECURITY.md
index d514399fce..efefa6e017 100644
--- a/docs/AGENT_SECURITY.md
+++ b/docs/AGENT_SECURITY.md
@@ -69,6 +69,7 @@ answers your monitoring question:
|---|---|---|
| PVE/PBS/PMG inventory, node status, VM/container status, storage usage, and normal Proxmox API metrics | Add the Proxmox connection with a read-only or narrowly scoped API token | No |
| VM guest disk and memory details through QEMU Guest Agent | Use Proxmox API permissions such as `VM.GuestAgent.Audit` and `VM.GuestAgent.FileRead` where supported | No host agent for the Proxmox node |
+| All mounted LXC filesystem capacities and usage | Install the Unified Agent on the owning PVE node; it automatically uses bounded `pct list` and `pct df` reads for running LXCs | Yes, on the PVE node |
| Docker/Podman containers inside a VM or LXC through guest-local reporting | Install the agent inside that VM/LXC with Docker/Podman monitoring enabled, or use another explicit guest access/reporting path | Usually requires root or Docker socket-equivalent access |
| Docker containers inside an LXC from a Proxmox host agent | Start Pulse with `PULSE_ENABLE_PROXMOX_GUEST_DOCKER_INVENTORY=true`; optionally limit guests with `PULSE_PROXMOX_GUEST_DOCKER_INVENTORY_VMIDS=101,102` | Requires a root/equivalent Pulse agent on the Proxmox node and explicit server opt-in |
| Host SMART, temperatures, local ZFS/Ceph/mdadm detail, arbitrary mount reads, and full host telemetry | Install the agent on that host | Yes, for the supported full-telemetry profile |
@@ -77,7 +78,15 @@ answers your monitoring question:
Inside-guest runtime visibility is explicit. Installing the agent inside a VM or
LXC authorizes that guest-local agent to report Docker/Podman monitoring data
according to its local module flags. A Proxmox node agent does not look inside
-LXCs by default. It can collect Docker container inventory from LXC guests
+LXCs by default. Its automatic LXC filesystem collector is a node-local
+capacity query only: it runs `pct list`, then `pct df <vmid>` for guests already
+reported running, and reports mount keys, volume labels, mount paths, and
+capacity/usage numbers. It does not run a command inside the guest or read
+guest files, processes, environment, or container-runtime metadata. It skips
+guests reported stopped and bounds command time, output, guest count, and disk
+count.
+
+The node agent can collect Docker container inventory from LXC guests
through `pct exec`, but only when the server is started with
`PULSE_ENABLE_PROXMOX_GUEST_DOCKER_INVENTORY=true`.
Inventory collection is disabled by default, can be VMID-allowlisted, and is
diff --git a/docs/UNIFIED_AGENT.md b/docs/UNIFIED_AGENT.md
index 5f81e8025d..3bbf335a9f 100644
--- a/docs/UNIFIED_AGENT.md
+++ b/docs/UNIFIED_AGENT.md
@@ -6,11 +6,11 @@ For API-backed platforms, start with the platform connection first and add the a
For Proxmox, install the agent only where you need telemetry that the Proxmox
API cannot provide, such as host SMART and temperature data, local
-ZFS/Ceph/mdadm detail, arbitrary mount reads, or inside-guest runtime
-visibility. Docker containers inside LXCs can be reported by a Proxmox host
-agent when the server has explicitly enabled the privacy-bounded LXC inventory
-mode; Docker/Podman inside VMs still needs a guest-local agent or another
-explicit guest reporting path.
+ZFS/Ceph/mdadm detail, arbitrary host mount reads, or the full mounted
+filesystem breakdown for running LXCs. Docker containers inside LXCs can be
+reported by a Proxmox host agent when the server has explicitly enabled the
+privacy-bounded LXC inventory mode; Docker/Podman inside VMs still needs a
+guest-local agent or another explicit guest reporting path.
Basic Proxmox inventory and utilization can use a read-only or narrowly scoped
Proxmox API token instead. Settings uses that API inventory path as the
default for new PVE/PBS setup. See [Agent Security](AGENT_SECURITY.md) for
@@ -403,7 +403,13 @@ Unified Agent in the guest when you want full Docker host, container, service,
and task inventory on the Docker page.
Pulse does not use a Proxmox node agent to look inside LXCs by default. The
-optional Proxmox-side LXC Docker hint is off unless the Pulse server is started
+node agent does automatically collect filesystem capacity for running LXCs
+when the local `pct` tool is available. It uses bounded `pct list` and
+`pct df <vmid>` calls and reports only mount keys, volume labels, mount paths,
+and capacity/usage values; it does not run commands inside a guest or read
+guest files. Stopped LXCs retain the normal API-derived disk view.
+
+The optional Proxmox-side LXC Docker hint is off unless the Pulse server is started
with `PULSE_ENABLE_PROXMOX_GUEST_DOCKER_DETECTION=true`. That hint uses
`pct exec` only to check whether `/var/run/docker.sock` exists in a running LXC;
it does not enumerate containers, images, environment variables, files, or
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 5a85756547..c931289c29 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -39,6 +39,14 @@ the JSON output option must retry the same probe in parseable text mode; DSM
standby evidence. Enumeration and each device probe have independent bounded
deadlines so one slow disk cannot consume the complete SMART pass, while
command errors retain bounded stderr for compatibility diagnosis.
+On a PVE node, the Unified Agent may also report the mounted filesystem
+capacity of running LXCs through the fixed local `pct list` and
+`pct df <vmid>` command set. This collector is automatic when `pct` is
+available, uses one shared deadline plus per-command byte ceilings, caps guest
+and disk counts, never accepts an unvalidated VMID as an argument, and does not
+invoke `pct df` for guests the preceding list reported stopped. The report
+carries VMID and exact container name so monitoring can reject stale migration
+or rename correlations.
`internal/monitoring/monitor.go` also serializes shared unified-resource
websocket payloads. Carrying plural availability facets through that serializer
is an adjacent monitoring/API projection and does not change agent enrollment,
@@ -98,6 +106,7 @@ observation.
5e. `internal/agentexec/verifier_postconditions.go`
5f. `pkg/agents/docker/report_limits.go`
5g. `internal/hostagent/xcpng.go`
+ 5h. `internal/hostagent/proxmox_lxc_filesystems.go`
6. `cmd/pulse-agent/main.go`
7. `scripts/install.sh`
8. `scripts/install.ps1`
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index 469e6ab1d4..be5eb6f62f 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -40,6 +40,15 @@ source-native `{instance}:{node}:{vmid}` IDs; a successful empty member
enumeration is authoritative and removes genuinely deleted guests. Collection
failure remains visible through source freshness/error state and must not be
converted into an authoritative empty inventory.
+Running LXC filesystem detail may be supplemented by a node-local Unified
+Agent report when the reporting host is securely linked to exactly one current
+PVE node. Monitoring admits only bounded, normalized VMID/name/disk rows,
+keys them by PVE instance, node, and VMID, and requires the subsequent API poll
+to match the exact container name and running state. Server receipt time owns
+the cadence-derived cache lease. Missing, expired, renamed, stopped, or
+migrated observations fall back to the Proxmox API disk view; a fresh accepted
+rootfs reading also replaces the row's primary disk summary before alerts and
+history are evaluated.
Host-agent report liveness is server-observed, not agent-clock-observed:
`ApplyHostReport` must stamp `Host.LastSeen`, agent-sourced Ceph cluster
freshness, and host-agent cluster sensor freshness from Pulse receipt time, so
@@ -394,6 +403,7 @@ changes.
32. `internal/monitoring/scheduler.go`
33. `internal/monitoring/docker_detection.go`
34. `internal/monitoring/monitor_polling_containers.go`
+34a. `internal/monitoring/monitor_agent_lxc_filesystems.go`
35. `internal/mock/fixture_graph.go`
35a. `internal/mock/action_fixtures.go`
35b. `internal/mock/availability_fixtures.go`
diff --git a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
index f0d77a2854..fe3e3dd17d 100644
--- a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
+++ b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
@@ -342,6 +342,10 @@ change may globally weaken the Task 03 lifecycle-state idempotency invariant.
the same startup-only router rule: env opt-in may configure monitoring-owned
checker/collector callbacks, but normal protected request setup must not run
`pct`, scan LXC guests, or collect Docker inventory.
+ Automatic LXC filesystem capacity collection remains outside that request
+ path in the node-local Unified Agent. It uses one shared deadline, fixed
+ output ceilings, and bounded running-guest/disk counts; monitoring merges
+ only a fresh in-memory node/VMID/name match during the existing PVE poll.
Source freshness threshold wiring in `internal/api/router.go` follows the
same bounded startup/config rule. Router construction may pass already-held
monitor config into the unified-resource adapter, but it must not add
diff --git a/docs/release-control/v6/internal/subsystems/security-privacy.md b/docs/release-control/v6/internal/subsystems/security-privacy.md
index 72cbd1e64e..ea912da16d 100644
--- a/docs/release-control/v6/internal/subsystems/security-privacy.md
+++ b/docs/release-control/v6/internal/subsystems/security-privacy.md
@@ -380,6 +380,13 @@ the `white_label` branding entitlement.
pinned-fingerprint TLS clients keep one fail-closed security floor.
9. Change operator-facing Resource Privacy/Data Handling posture through `frontend-modern/src/components/Settings/DataHandlingPanel.tsx` and `frontend-modern/src/components/Settings/dataHandlingPanelModel.ts` together so resource classification, handling-boundary, redaction copy, and the route-backed/hidden-sidebar presentation stay governed as a trust surface.
10. Change inside-guest runtime collection boundaries through `docs/AGENT_SECURITY.md`, `docs/UNIFIED_AGENT.md`, `cmd/pulse-agent/main.go`, `internal/api/router.go`, and `internal/config/config.go` together. Docker / Podman inventory inside a VM or LXC may come from a guest-local `pulse-agent` module or explicitly reported guest data; LXC Docker inventory may also be collected by a Proxmox host agent only through explicit server opt-in, with optional VMID allowlisting and a minimal summary command set that avoids `docker inspect`, environment, mount, file, command, and process collection. Local Unified Agent Docker / Podman disables must not be reversed by remote profile configuration, and self-test/update preflight that needs the live runtime token must pass it through a short-lived token file rather than argv. The `--enable-docker` help line is part of that operator privacy control, so it must remain "Enable Docker / Podman Agent module" instead of exposing internal collection-module wording. The `--enable-commands` help line and installer disclosure must identify Pulse command execution as disabled by default and required for Patrol actions or the explicit Proxmox LXC Docker inventory path, not as implicit guest access.
+ Node-local LXC filesystem capacity is a distinct automatic host telemetry
+ boundary, not inside-guest command authority. A PVE Unified Agent may use
+ bounded `pct list` plus `pct df` only for guests reported running and may
+ report only VMID, exact guest name, mount key, volume label, mount path,
+ and capacity/usage values. That path must not use `pct exec`, read guest
+ file contents, or collect guest processes, environment, commands, or
+ container-runtime inventory.
Agent file logging is local operational state, not a second telemetry path:
`cmd/pulse-agent/main.go` must use the canonical owner-only rotating sink,
retain that sink when remote configuration changes log level, and never
diff --git a/internal/hostagent/agent.go b/internal/hostagent/agent.go
index d775bc2721..6128cb53bd 100644
--- a/internal/hostagent/agent.go
+++ b/internal/hostagent/agent.go
@@ -1123,6 +1123,10 @@ func (a *Agent) buildReport(ctx context.Context) (agentshost.Report, error) {
// normal host report.
xcpngData := a.collectXCPNGInventory(ctx)
+ // Proxmox VE exposes per-mount LXC usage only through the node-local pct
+ // CLI. Query running containers on an independent bounded deadline.
+ proxmoxLXCData := a.collectProxmoxLXCFilesystems(ctx)
+
// Collect S.M.A.R.T. disk data after topology owners. Enumeration and each
// device probe have their own deadlines; a single shared 10-second budget
// caused later disks on larger arrays to be cancelled before their probe.
@@ -1167,6 +1171,14 @@ func (a *Agent) buildReport(ctx context.Context) (agentshost.Report, error) {
UpdatedAt: xcpngData.CollectedAt,
})
}
+ if proxmoxLXCData != nil {
+ moduleStatus = append(moduleStatus, agentshost.ModuleStatus{
+ Name: "proxmox-lxc-filesystems",
+ Enabled: true,
+ State: "running",
+ UpdatedAt: proxmoxLXCData.CollectedAt,
+ })
+ }
report := agentshost.Report{
Agent: agentshost.AgentInfo{
@@ -1214,6 +1226,7 @@ func (a *Agent) buildReport(ctx context.Context) (agentshost.Report, error) {
Ceph: cephData,
Libvirt: libvirtData,
XCPNG: xcpngData,
+ ProxmoxLXC: proxmoxLXCData,
ClusterSensors: clusterSensors,
// Results stay queued until the primary destination accepts this
// report, so a delivery failure retries them instead of losing them.
diff --git a/internal/hostagent/agent_metrics_test.go b/internal/hostagent/agent_metrics_test.go
index 86eaa043db..3f7fee5bc4 100644
--- a/internal/hostagent/agent_metrics_test.go
+++ b/internal/hostagent/agent_metrics_test.go
@@ -3,9 +3,11 @@ package hostagent
import (
"context"
"errors"
+ "fmt"
"net/http"
"net/http/httptest"
"os"
+ "strings"
"testing"
"time"
@@ -689,6 +691,81 @@ func TestBuildReportIncludesNVIDIASMITelemetryOnWindows(t *testing.T) {
}
}
+func TestBuildReportIncludesProxmoxLXCFilesystems(t *testing.T) {
+ const pctPath = "/usr/sbin/pct"
+ now := time.Date(2026, 7, 30, 20, 30, 0, 0, time.UTC)
+ mc := &mockCollector{
+ goos: "linux",
+ nowFn: func() time.Time { return now },
+ hostInfoFn: func(context.Context) (*gohost.InfoStat, error) {
+ return &gohost.InfoStat{
+ Hostname: "pve-a",
+ HostID: "pve-a-id",
+ Platform: "debian",
+ }, nil
+ },
+ lookPathFn: func(file string) (string, error) {
+ if file == "pct" {
+ return pctPath, nil
+ }
+ return "", os.ErrNotExist
+ },
+ commandCombinedOutputLimitedFn: func(
+ _ context.Context,
+ _ int,
+ name string,
+ args ...string,
+ ) (string, error) {
+ if name != pctPath {
+ return "", os.ErrNotExist
+ }
+ switch strings.Join(args, " ") {
+ case "list":
+ return fmt.Sprintf(
+ "%-10s %-10s %-12s %-20s\n%-10d %-10s %-12s %-20s\n",
+ "VMID", "Status", "Lock", "Name",
+ 200, "running", "", "app",
+ ), nil
+ case "df 200":
+ return "MP Volume Size Used Avail Use% Path\nrootfs local:subvol-200-disk-0 20.0G 5.0G 15.0G 25.0 /\n", nil
+ default:
+ return "", fmt.Errorf("unexpected pct args: %v", args)
+ }
+ },
+ }
+ agent, err := New(Config{
+ AgentID: "pve-a-agent",
+ APIToken: "token",
+ LogLevel: -1,
+ Collector: mc,
+ })
+ if err != nil {
+ t.Fatalf("New() failed: %v", err)
+ }
+
+ report, err := agent.buildReport(context.Background())
+ if err != nil {
+ t.Fatalf("buildReport failed: %v", err)
+ }
+ if report.ProxmoxLXC == nil || len(report.ProxmoxLXC.Containers) != 1 {
+ t.Fatalf("Proxmox LXC inventory = %+v", report.ProxmoxLXC)
+ }
+ if report.ProxmoxLXC.Containers[0].VMID != 200 ||
+ len(report.ProxmoxLXC.Containers[0].Disks) != 1 ||
+ report.ProxmoxLXC.Containers[0].Disks[0].Mountpoint != "/" {
+ t.Fatalf("Proxmox LXC container = %+v", report.ProxmoxLXC.Containers[0])
+ }
+ foundModule := false
+ for _, module := range report.Agent.Modules {
+ if module.Name == "proxmox-lxc-filesystems" && module.State == "running" {
+ foundModule = true
+ }
+ }
+ if !foundModule {
+ t.Fatalf("agent modules = %+v, want Proxmox LXC filesystem module", report.Agent.Modules)
+ }
+}
+
func TestBuildReportUsesResolvedNASOSIdentity(t *testing.T) {
fixedTime := time.Date(2026, time.April, 15, 12, 0, 0, 0, time.UTC)
diff --git a/internal/hostagent/proxmox_lxc_filesystems.go b/internal/hostagent/proxmox_lxc_filesystems.go
new file mode 100644
index 0000000000..8f3b975c97
--- /dev/null
+++ b/internal/hostagent/proxmox_lxc_filesystems.go
@@ -0,0 +1,305 @@
+package hostagent
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "math"
+ "os"
+ "os/exec"
+ "path"
+ "sort"
+ "strconv"
+ "strings"
+ "time"
+ "unicode/utf8"
+
+ agentshost "github.com/rcourtman/pulse-go-rewrite/pkg/agents/host"
+)
+
+const (
+ proxmoxLXCQueryTimeout = 10 * time.Second
+ proxmoxLXCMaxContainers = 128
+ proxmoxLXCMaxDisks = 257
+ proxmoxLXCMaxListOutputBytes = 64 * 1024
+ proxmoxLXCMaxDFOutputBytes = 64 * 1024
+ proxmoxLXCMaxNameBytes = 256
+ proxmoxLXCMaxLabelBytes = 512
+)
+
+type proxmoxLXCRunningContainer struct {
+ VMID int
+ Name string
+}
+
+// collectProxmoxLXCFilesystems auto-detects the local Proxmox Container
+// Toolkit. It lists node-local guests, then runs pct df only for containers
+// that the same list reported as running. Collection is read-only and
+// best-effort; a failed per-container query does not suppress other results.
+func (a *Agent) collectProxmoxLXCFilesystems(ctx context.Context) *agentshost.ProxmoxLXCInventory {
+ if a.collector.GOOS() != "linux" {
+ return nil
+ }
+ pctPath, err := a.collector.LookPath("pct")
+ if err != nil {
+ if !errors.Is(err, exec.ErrNotFound) && !os.IsNotExist(err) {
+ a.logger.Debug().Err(err).Msg("Failed to locate pct for Proxmox LXC filesystems")
+ }
+ return nil
+ }
+
+ queryCtx, cancel := context.WithTimeout(ctx, proxmoxLXCQueryTimeout)
+ defer cancel()
+
+ listOutput, err := collectCommandOutputLimited(
+ queryCtx,
+ a.collector,
+ proxmoxLXCMaxListOutputBytes,
+ pctPath,
+ "list",
+ )
+ if err != nil {
+ a.logger.Debug().Err(err).Msg("Failed to list local Proxmox LXC containers")
+ return nil
+ }
+ containers, err := parseProxmoxLXCRunningContainers(listOutput)
+ if err != nil {
+ a.logger.Debug().Err(err).Msg("Failed to parse local Proxmox LXC container list")
+ return nil
+ }
+
+ inventory := &agentshost.ProxmoxLXCInventory{
+ Containers: []agentshost.ProxmoxLXCContainer{},
+ CollectedAt: a.collector.Now().UTC(),
+ }
+ for _, container := range containers {
+ if queryCtx.Err() != nil {
+ break
+ }
+ output, outputErr := collectCommandOutputLimited(
+ queryCtx,
+ a.collector,
+ proxmoxLXCMaxDFOutputBytes,
+ pctPath,
+ "df",
+ strconv.Itoa(container.VMID),
+ )
+ if outputErr != nil {
+ a.logger.Debug().
+ Err(outputErr).
+ Int("vmid", container.VMID).
+ Msg("Failed to collect Proxmox LXC filesystem usage")
+ continue
+ }
+ disks, parseErr := parseProxmoxLXCDF(output)
+ if parseErr != nil || len(disks) == 0 {
+ a.logger.Debug().
+ Err(parseErr).
+ Int("vmid", container.VMID).
+ Msg("Failed to parse Proxmox LXC filesystem usage")
+ continue
+ }
+ inventory.Containers = append(inventory.Containers, agentshost.ProxmoxLXCContainer{
+ VMID: container.VMID,
+ Name: container.Name,
+ Disks: disks,
+ })
+ }
+
+ return inventory
+}
+
+func parseProxmoxLXCRunningContainers(output string) ([]proxmoxLXCRunningContainer, error) {
+ if len(output) > proxmoxLXCMaxListOutputBytes {
+ return nil, fmt.Errorf("pct list output exceeds %d bytes", proxmoxLXCMaxListOutputBytes)
+ }
+
+ result := make([]proxmoxLXCRunningContainer, 0)
+ seen := make(map[int]struct{})
+ for _, rawLine := range strings.Split(output, "\n") {
+ line := strings.TrimSuffix(rawLine, "\r")
+ if strings.TrimSpace(line) == "" || strings.HasPrefix(strings.TrimSpace(line), "VMID") {
+ continue
+ }
+
+ fields := strings.Fields(line)
+ if len(fields) < 2 || !strings.EqualFold(fields[1], "running") {
+ continue
+ }
+ vmid, err := strconv.Atoi(fields[0])
+ if err != nil || vmid < 100 || vmid > 999999999 {
+ continue
+ }
+ if _, exists := seen[vmid]; exists {
+ continue
+ }
+
+ name := ""
+ if len(line) > 35 {
+ name = strings.TrimSpace(line[35:])
+ } else if len(fields) >= 3 {
+ name = fields[len(fields)-1]
+ }
+ if !safeProxmoxLXCText(name, proxmoxLXCMaxNameBytes) {
+ continue
+ }
+
+ seen[vmid] = struct{}{}
+ result = append(result, proxmoxLXCRunningContainer{VMID: vmid, Name: name})
+ if len(result) == proxmoxLXCMaxContainers {
+ break
+ }
+ }
+ sort.Slice(result, func(i, j int) bool { return result[i].VMID < result[j].VMID })
+ return result, nil
+}
+
+func parseProxmoxLXCDF(output string) ([]agentshost.Disk, error) {
+ if len(output) > proxmoxLXCMaxDFOutputBytes {
+ return nil, fmt.Errorf("pct df output exceeds %d bytes", proxmoxLXCMaxDFOutputBytes)
+ }
+
+ result := make([]agentshost.Disk, 0)
+ seen := make(map[string]struct{})
+ for _, rawLine := range strings.Split(output, "\n") {
+ line := strings.TrimSpace(strings.TrimSuffix(rawLine, "\r"))
+ if line == "" || strings.HasPrefix(line, "MP ") {
+ continue
+ }
+ fields := strings.Fields(line)
+ if len(fields) < 7 {
+ continue
+ }
+
+ diskType := strings.ToLower(strings.TrimSpace(fields[0]))
+ if diskType != "rootfs" && !validProxmoxLXCMountKey(diskType) {
+ continue
+ }
+ device := strings.TrimSpace(fields[1])
+ if !safeProxmoxLXCText(device, proxmoxLXCMaxLabelBytes) {
+ continue
+ }
+ total, totalOK := parseProxmoxLXCSize(fields[2])
+ used, usedOK := parseProxmoxLXCSize(fields[3])
+ free, freeOK := parseProxmoxLXCSize(fields[4])
+ usage, usageOK := parseProxmoxLXCUsage(fields[5])
+ if !totalOK || !usedOK || !freeOK || !usageOK || total <= 0 {
+ continue
+ }
+ if used > total {
+ used = total
+ }
+ if free > total {
+ free = total
+ }
+
+ mountpoint := strings.TrimSpace(strings.Join(fields[6:], " "))
+ if !validProxmoxLXCMountpoint(mountpoint) {
+ continue
+ }
+ key := strings.ToLower(mountpoint)
+ if _, exists := seen[key]; exists {
+ continue
+ }
+ seen[key] = struct{}{}
+
+ result = append(result, agentshost.Disk{
+ Device: device,
+ Mountpoint: mountpoint,
+ Type: diskType,
+ TotalBytes: total,
+ UsedBytes: used,
+ FreeBytes: free,
+ Usage: usage,
+ })
+ if len(result) == proxmoxLXCMaxDisks {
+ break
+ }
+ }
+
+ sort.SliceStable(result, func(i, j int) bool {
+ if result[i].Mountpoint == "/" {
+ return true
+ }
+ if result[j].Mountpoint == "/" {
+ return false
+ }
+ return result[i].Mountpoint < result[j].Mountpoint
+ })
+ if len(result) == 0 {
+ return nil, nil
+ }
+ return result, nil
+}
+
+func parseProxmoxLXCSize(value string) (int64, bool) {
+ value = strings.TrimSpace(value)
+ if value == "" {
+ return 0, false
+ }
+
+ multiplier := float64(1)
+ last := value[len(value)-1]
+ switch last {
+ case 'K', 'k':
+ multiplier = 1 << 10
+ case 'M', 'm':
+ multiplier = 1 << 20
+ case 'G', 'g':
+ multiplier = 1 << 30
+ case 'T', 't':
+ multiplier = 1 << 40
+ default:
+ last = 0
+ }
+ if last != 0 {
+ value = strings.TrimSpace(value[:len(value)-1])
+ }
+ parsed, err := strconv.ParseFloat(value, 64)
+ if err != nil || math.IsNaN(parsed) || math.IsInf(parsed, 0) || parsed < 0 {
+ return 0, false
+ }
+ bytes := parsed * multiplier
+ if bytes > math.MaxInt64 {
+ return 0, false
+ }
+ return int64(math.Round(bytes)), true
+}
+
+func parseProxmoxLXCUsage(value string) (float64, bool) {
+ value = strings.TrimSuffix(strings.TrimSpace(value), "%")
+ parsed, err := strconv.ParseFloat(value, 64)
+ if err != nil || math.IsNaN(parsed) || math.IsInf(parsed, 0) || parsed < 0 || parsed > 100 {
+ return 0, false
+ }
+ return parsed, true
+}
+
+func validProxmoxLXCMountKey(value string) bool {
+ if !strings.HasPrefix(value, "mp") || len(value) < 3 || len(value) > 5 {
+ return false
+ }
+ index, err := strconv.Atoi(value[2:])
+ return err == nil && index >= 0 && index <= 255
+}
+
+func validProxmoxLXCMountpoint(value string) bool {
+ if !safeProxmoxLXCText(value, proxmoxLXCMaxLabelBytes) || !strings.HasPrefix(value, "/") {
+ return false
+ }
+ cleaned := path.Clean(value)
+ return cleaned == value && !strings.Contains(value, "\x00")
+}
+
+func safeProxmoxLXCText(value string, maxBytes int) bool {
+ value = strings.TrimSpace(value)
+ if value == "" || len(value) > maxBytes || !utf8.ValidString(value) {
+ return false
+ }
+ for _, char := range value {
+ if char < 0x20 || char == 0x7f {
+ return false
+ }
+ }
+ return true
+}
diff --git a/internal/hostagent/proxmox_lxc_filesystems_test.go b/internal/hostagent/proxmox_lxc_filesystems_test.go
new file mode 100644
index 0000000000..5b74814ec4
--- /dev/null
+++ b/internal/hostagent/proxmox_lxc_filesystems_test.go
@@ -0,0 +1,138 @@
+package hostagent
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "os"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/rs/zerolog"
+)
+
+func TestCollectProxmoxLXCFilesystemsUsesBoundedRunningPctQueries(t *testing.T) {
+ const pctPath = "/usr/sbin/pct"
+ listOutput := fmt.Sprintf(
+ "%-10s %-10s %-12s %-20s\n%-10d %-10s %-12s %-20s\n%-10d %-10s %-12s %-20s\n%-10d %-10s %-12s %-20s\n",
+ "VMID", "Status", "Lock", "Name",
+ 100, "running", "", "web",
+ 101, "stopped", "", "archive",
+ 102, "running", "backup", "database",
+ )
+ now := time.Date(2026, 7, 30, 20, 0, 0, 0, time.UTC)
+ var commands [][]string
+ collector := &mockCollector{
+ goos: "linux",
+ nowFn: func() time.Time { return now },
+ lookPathFn: func(file string) (string, error) {
+ if file == "pct" {
+ return pctPath, nil
+ }
+ return "", os.ErrNotExist
+ },
+ commandCombinedOutputLimitedFn: func(
+ _ context.Context,
+ maxBytes int,
+ name string,
+ args ...string,
+ ) (string, error) {
+ if name != pctPath {
+ t.Fatalf("command path = %q, want %q", name, pctPath)
+ }
+ commands = append(commands, append([]string(nil), args...))
+ switch strings.Join(args, " ") {
+ case "list":
+ if maxBytes != proxmoxLXCMaxListOutputBytes {
+ t.Fatalf("pct list limit = %d", maxBytes)
+ }
+ return listOutput, nil
+ case "df 100":
+ if maxBytes != proxmoxLXCMaxDFOutputBytes {
+ t.Fatalf("pct df limit = %d", maxBytes)
+ }
+ return `MP Volume Size Used Avail Use% Path
+rootfs local-lvm:vm-100-disk-0 8.0G 2.0G 6.0G 25.0 /
+mp0 tank:subvol-100-disk-0 1.0T 512.0G 512.0G 50.0 /srv/data
+`, nil
+ case "df 102":
+ return "", errors.New("container migrated")
+ default:
+ t.Fatalf("unexpected pct command: %v", args)
+ return "", nil
+ }
+ },
+ }
+ agent := &Agent{logger: zerolog.Nop(), collector: collector}
+
+ got := agent.collectProxmoxLXCFilesystems(context.Background())
+ if got == nil || !got.CollectedAt.Equal(now) {
+ t.Fatalf("inventory = %+v", got)
+ }
+ if len(commands) != 3 {
+ t.Fatalf("commands = %v, want list plus two running df queries", commands)
+ }
+ for _, command := range commands {
+ if len(command) == 2 && command[1] == "101" {
+ t.Fatalf("stopped container was queried: %v", commands)
+ }
+ }
+ if len(got.Containers) != 1 || got.Containers[0].VMID != 100 || got.Containers[0].Name != "web" {
+ t.Fatalf("containers = %+v", got.Containers)
+ }
+ if len(got.Containers[0].Disks) != 2 {
+ t.Fatalf("disks = %+v", got.Containers[0].Disks)
+ }
+ root := got.Containers[0].Disks[0]
+ if root.Mountpoint != "/" || root.Device != "local-lvm:vm-100-disk-0" ||
+ root.TotalBytes != 8<<30 || root.UsedBytes != 2<<30 || root.Usage != 25 {
+ t.Fatalf("root disk = %+v", root)
+ }
+ data := got.Containers[0].Disks[1]
+ if data.Mountpoint != "/srv/data" || data.Type != "mp0" ||
+ data.TotalBytes != 1<<40 || data.FreeBytes != 512<<30 {
+ t.Fatalf("data disk = %+v", data)
+ }
+}
+
+func TestParseProxmoxLXCFilesystemsValidatesAndBoundsInput(t *testing.T) {
+ list := fmt.Sprintf(
+ "%-10s %-10s %-12s %-20s\n%-10d %-10s %-12s %-20s\n%-10d %-10s %-12s %-20s\n",
+ "VMID", "Status", "Lock", "Name",
+ 99, "running", "", "too-small",
+ 100, "running", "", "valid",
+ )
+ containers, err := parseProxmoxLXCRunningContainers(list)
+ if err != nil {
+ t.Fatalf("parse list: %v", err)
+ }
+ if len(containers) != 1 || containers[0].VMID != 100 || containers[0].Name != "valid" {
+ t.Fatalf("running containers = %+v", containers)
+ }
+ if _, err := parseProxmoxLXCRunningContainers(
+ strings.Repeat("x", proxmoxLXCMaxListOutputBytes+1),
+ ); err == nil {
+ t.Fatal("expected oversized pct list error")
+ }
+
+ disks, err := parseProxmoxLXCDF(`MP Volume Size Used Avail Use% Path
+mp1 pool:valid 10.0G 4.0G 6.0G 40.0 /valid
+mp2 pool:duplicate 10.0G 5.0G 5.0G 50.0 /valid
+mp256 pool:bad 10.0G 1.0G 9.0G 10.0 /too-many
+mp3 pool:relative 10.0G 1.0G 9.0G 10.0 relative
+mp4 pool:traversal 10.0G 1.0G 9.0G 10.0 /srv/../etc
+mp5 pool:hot 10.0G 1.0G 9.0G 101.0 /hot
+`)
+ if err != nil {
+ t.Fatalf("parse df: %v", err)
+ }
+ if len(disks) != 1 || disks[0].Mountpoint != "/valid" {
+ t.Fatalf("validated disks = %+v", disks)
+ }
+ if _, err := parseProxmoxLXCDF(
+ strings.Repeat("x", proxmoxLXCMaxDFOutputBytes+1),
+ ); err == nil {
+ t.Fatal("expected oversized pct df error")
+ }
+}
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index 1c756ed229..30171b6092 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -1173,6 +1173,11 @@ type Monitor struct {
// Agent profile cache to avoid disk I/O on every report (refs #1094)
agentProfileCacheMu sync.RWMutex
agentProfileCache *agentProfileCacheEntry
+ // Proxmox LXC filesystem cache: bounded pct df readings reported by an
+ // agent securely linked to the node that owns each running container.
+ proxmoxLXCFilesystemsMu sync.RWMutex
+ proxmoxLXCFilesystemsCache map[string]agentLXCFilesystemCacheEntry
+
// Cluster sensor cache: temperature data collected by an agent on one Proxmox
// cluster node via SSH to its siblings. Keyed by lowercase node name.
clusterSensorsMu sync.RWMutex
@@ -1677,6 +1682,7 @@ func New(cfg *config.Config) (*Monitor, error) {
hostReportApplyLocks: make(map[string]*hostReportApplyLock),
hostReportOrders: make(map[string]hostReportOrder),
clusterSensorsCache: make(map[string]clusterSensorsCacheEntry),
+ proxmoxLXCFilesystemsCache: make(map[string]agentLXCFilesystemCacheEntry),
dockerCommands: make(map[string]*dockerHostCommand),
dockerCommandIndex: make(map[string]string),
guestMetadataCache: make(map[string]guestMetadataCacheEntry),
diff --git a/internal/monitoring/monitor_agent_lxc_filesystems.go b/internal/monitoring/monitor_agent_lxc_filesystems.go
new file mode 100644
index 0000000000..86f2027fa9
--- /dev/null
+++ b/internal/monitoring/monitor_agent_lxc_filesystems.go
@@ -0,0 +1,259 @@
+package monitoring
+
+import (
+ "path"
+ "sort"
+ "strconv"
+ "strings"
+ "time"
+ "unicode/utf8"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/models"
+ agentshost "github.com/rcourtman/pulse-go-rewrite/pkg/agents/host"
+)
+
+const (
+ agentLXCFilesystemMinTTL = 3 * time.Minute
+ agentLXCFilesystemMaxTTL = 15 * time.Minute
+ agentLXCFilesystemMaxContainers = 128
+ agentLXCFilesystemMaxDisks = 257
+ agentLXCFilesystemMaxNameBytes = 256
+ agentLXCFilesystemMaxLabelBytes = 512
+)
+
+type agentLXCFilesystemCacheEntry struct {
+ agentID string
+ name string
+ disks []models.Disk
+ expiresAt time.Time
+}
+
+func agentLXCFilesystemCacheKey(instance, node string, vmid int) string {
+ return strings.ToLower(strings.TrimSpace(instance)) + "\x00" +
+ strings.ToLower(strings.TrimSpace(node)) + "\x00" +
+ strconv.Itoa(vmid)
+}
+
+func agentLXCFilesystemTTL(intervalSeconds int) time.Duration {
+ ttl := time.Duration(intervalSeconds) * 3 * time.Second
+ if ttl < agentLXCFilesystemMinTTL {
+ return agentLXCFilesystemMinTTL
+ }
+ if ttl > agentLXCFilesystemMaxTTL {
+ return agentLXCFilesystemMaxTTL
+ }
+ return ttl
+}
+
+// applyAgentLXCFilesystems admits node-local pct df data only when the
+// reporting host agent is already linked to exactly one current Proxmox node.
+// Receipt time, rather than the agent clock, controls freshness.
+func (m *Monitor) applyAgentLXCFilesystems(
+ linkedNodeID string,
+ agentID string,
+ inventory *agentshost.ProxmoxLXCInventory,
+ receivedAt time.Time,
+ intervalSeconds int,
+) {
+ agentID = strings.TrimSpace(agentID)
+ if m == nil || m.state == nil || inventory == nil ||
+ strings.TrimSpace(linkedNodeID) == "" || agentID == "" {
+ return
+ }
+
+ var linkedNodes []models.Node
+ for _, node := range m.state.GetSnapshot().Nodes {
+ if node.ID == linkedNodeID {
+ linkedNodes = append(linkedNodes, node)
+ }
+ }
+ if len(linkedNodes) != 1 {
+ return
+ }
+ node := linkedNodes[0]
+ if strings.TrimSpace(node.Instance) == "" || strings.TrimSpace(node.Name) == "" {
+ return
+ }
+
+ if receivedAt.IsZero() {
+ receivedAt = time.Now()
+ }
+ expiresAt := receivedAt.Add(agentLXCFilesystemTTL(intervalSeconds))
+ limit := len(inventory.Containers)
+ if limit > agentLXCFilesystemMaxContainers {
+ limit = agentLXCFilesystemMaxContainers
+ }
+
+ updates := make(map[string]agentLXCFilesystemCacheEntry, limit)
+ for _, container := range inventory.Containers[:limit] {
+ name := strings.TrimSpace(container.Name)
+ if container.VMID < 100 || container.VMID > 999999999 ||
+ !safeAgentLXCFilesystemText(name, agentLXCFilesystemMaxNameBytes) {
+ continue
+ }
+ disks := normalizeAgentLXCFilesystems(container.Disks)
+ if len(disks) == 0 {
+ continue
+ }
+ updates[agentLXCFilesystemCacheKey(node.Instance, node.Name, container.VMID)] =
+ agentLXCFilesystemCacheEntry{
+ agentID: agentID,
+ name: name,
+ disks: disks,
+ expiresAt: expiresAt,
+ }
+ }
+ m.proxmoxLXCFilesystemsMu.Lock()
+ defer m.proxmoxLXCFilesystemsMu.Unlock()
+ if m.proxmoxLXCFilesystemsCache == nil {
+ m.proxmoxLXCFilesystemsCache = make(map[string]agentLXCFilesystemCacheEntry)
+ }
+ for key, entry := range m.proxmoxLXCFilesystemsCache {
+ if !receivedAt.Before(entry.expiresAt) {
+ delete(m.proxmoxLXCFilesystemsCache, key)
+ }
+ }
+ for key, entry := range updates {
+ m.proxmoxLXCFilesystemsCache[key] = entry
+ }
+}
+
+func normalizeAgentLXCFilesystems(disks []agentshost.Disk) []models.Disk {
+ limit := len(disks)
+ if limit > agentLXCFilesystemMaxDisks {
+ limit = agentLXCFilesystemMaxDisks
+ }
+
+ result := make([]models.Disk, 0, limit)
+ seenMountpoints := make(map[string]struct{}, limit)
+ for _, disk := range disks[:limit] {
+ diskType := strings.ToLower(strings.TrimSpace(disk.Type))
+ mountpoint := strings.TrimSpace(disk.Mountpoint)
+ device := strings.TrimSpace(disk.Device)
+ if diskType != "rootfs" && !validAgentLXCMountKey(diskType) {
+ continue
+ }
+ if !validAgentLXCMountpoint(mountpoint) ||
+ !safeAgentLXCFilesystemText(device, agentLXCFilesystemMaxLabelBytes) ||
+ disk.TotalBytes <= 0 ||
+ disk.UsedBytes < 0 ||
+ disk.FreeBytes < 0 {
+ continue
+ }
+ mountpointKey := strings.ToLower(mountpoint)
+ if _, exists := seenMountpoints[mountpointKey]; exists {
+ continue
+ }
+ seenMountpoints[mountpointKey] = struct{}{}
+
+ used := disk.UsedBytes
+ if used > disk.TotalBytes {
+ used = disk.TotalBytes
+ }
+ free := disk.FreeBytes
+ if free > disk.TotalBytes {
+ free = disk.TotalBytes
+ }
+ result = append(result, models.Disk{
+ Total: disk.TotalBytes,
+ Used: used,
+ Free: free,
+ Usage: safePercentage(float64(used), float64(disk.TotalBytes)),
+ Mountpoint: mountpoint,
+ Type: diskType,
+ Device: device,
+ })
+ }
+
+ sort.SliceStable(result, func(i, j int) bool {
+ if result[i].Mountpoint == "/" {
+ return true
+ }
+ if result[j].Mountpoint == "/" {
+ return false
+ }
+ return result[i].Mountpoint < result[j].Mountpoint
+ })
+ return result
+}
+
+func (m *Monitor) enrichContainerWithAgentLXCFilesystems(
+ instance string,
+ node string,
+ container *models.Container,
+ now time.Time,
+) {
+ if m == nil || container == nil || !strings.EqualFold(strings.TrimSpace(container.Status), "running") {
+ return
+ }
+ key := agentLXCFilesystemCacheKey(instance, node, container.VMID)
+
+ m.proxmoxLXCFilesystemsMu.RLock()
+ entry, exists := m.proxmoxLXCFilesystemsCache[key]
+ m.proxmoxLXCFilesystemsMu.RUnlock()
+ if !exists {
+ return
+ }
+ if now.IsZero() {
+ now = time.Now()
+ }
+ if !now.Before(entry.expiresAt) {
+ m.proxmoxLXCFilesystemsMu.Lock()
+ if current, ok := m.proxmoxLXCFilesystemsCache[key]; ok && !now.Before(current.expiresAt) {
+ delete(m.proxmoxLXCFilesystemsCache, key)
+ }
+ m.proxmoxLXCFilesystemsMu.Unlock()
+ return
+ }
+ if strings.TrimSpace(container.Name) != entry.name {
+ return
+ }
+
+ container.Disks = append([]models.Disk(nil), entry.disks...)
+ for _, disk := range container.Disks {
+ if disk.Mountpoint == "/" {
+ container.Disk = disk
+ break
+ }
+ }
+}
+
+func (m *Monitor) clearAgentLXCFilesystems(agentID string) {
+ if m == nil || strings.TrimSpace(agentID) == "" {
+ return
+ }
+ m.proxmoxLXCFilesystemsMu.Lock()
+ defer m.proxmoxLXCFilesystemsMu.Unlock()
+ for key, entry := range m.proxmoxLXCFilesystemsCache {
+ if entry.agentID == agentID {
+ delete(m.proxmoxLXCFilesystemsCache, key)
+ }
+ }
+}
+
+func validAgentLXCMountKey(value string) bool {
+ if !strings.HasPrefix(value, "mp") || len(value) < 3 || len(value) > 5 {
+ return false
+ }
+ index, err := strconv.Atoi(value[2:])
+ return err == nil && index >= 0 && index <= 255
+}
+
+func validAgentLXCMountpoint(value string) bool {
+ return safeAgentLXCFilesystemText(value, agentLXCFilesystemMaxLabelBytes) &&
+ strings.HasPrefix(value, "/") &&
+ path.Clean(value) == value
+}
+
+func safeAgentLXCFilesystemText(value string, maxBytes int) bool {
+ value = strings.TrimSpace(value)
+ if value == "" || len(value) > maxBytes || !utf8.ValidString(value) {
+ return false
+ }
+ for _, char := range value {
+ if char < 0x20 || char == 0x7f {
+ return false
+ }
+ }
+ return true
+}
diff --git a/internal/monitoring/monitor_agents.go b/internal/monitoring/monitor_agents.go
index 429c69d906..a24f4cf701 100644
--- a/internal/monitoring/monitor_agents.go
+++ b/internal/monitoring/monitor_agents.go
@@ -471,6 +471,7 @@ func (m *Monitor) RemoveHostAgent(hostID string) (models.Host, error) {
// Clear LinkedAgentID from any nodes that were linked to this host agent
unlinkedCount := m.state.UnlinkNodesFromHostAgent(hostID)
+ m.clearAgentLXCFilesystems(hostID)
if unlinkedCount > 0 {
log.Info().
Str("hostID", hostID).
@@ -2319,6 +2320,7 @@ func (m *Monitor) supersedeStaleHostAgentDuplicates(current models.Host, tokenRe
}
m.state.RemoveConnectionHealth(hostConnectionPrefix + staleID)
m.state.UnlinkNodesFromHostAgent(staleID)
+ m.clearAgentLXCFilesystems(staleID)
m.mu.Lock()
for key, boundID := range m.hostTokenBindings {
@@ -2931,6 +2933,13 @@ func (m *Monitor) ApplyHostReport(report agentshost.Report, tokenRecord *config.
// Update the linked PVE node to point back to this host agent
if host.LinkedNodeID != "" {
m.linkNodeToHostAgent(host.LinkedNodeID, host.ID)
+ m.applyAgentLXCFilesystems(
+ host.LinkedNodeID,
+ host.ID,
+ report.ProxmoxLXC,
+ receivedAt,
+ report.Agent.IntervalSeconds,
+ )
}
// If host reports Ceph data, also update the global CephClusters state
diff --git a/internal/monitoring/monitor_host_agents_test.go b/internal/monitoring/monitor_host_agents_test.go
index 5308d6a380..0459c49f6f 100644
--- a/internal/monitoring/monitor_host_agents_test.go
+++ b/internal/monitoring/monitor_host_agents_test.go
@@ -867,6 +867,7 @@ func TestUnifiedAgentHostAndDockerReportsShareOneCanonicalMachine(t *testing.T)
}
})
}
+
}
func TestDockerOnlyAgentRemainsWorkloadOnly(t *testing.T) {
@@ -4721,3 +4722,185 @@ func TestNormalizeAgentXCPNGInventoryBoundsAndPreservesFailures(t *testing.T) {
t.Fatal("preserved inventory aliases previous host state")
}
}
+
+func TestAgentLXCFilesystemsRequireLinkedNodeAndExactRunningGuest(t *testing.T) {
+ now := time.Date(2026, 7, 30, 21, 0, 0, 0, time.UTC)
+ state := models.NewState()
+ state.UpdateNodes([]models.Node{{
+ ID: "pve-a:node-a",
+ Name: "node-a",
+ Instance: "pve-a",
+ LinkedAgentID: "agent-a",
+ }})
+ monitor := &Monitor{state: state}
+ monitor.applyAgentLXCFilesystems(
+ "pve-a:node-a",
+ "agent-a",
+ &agentshost.ProxmoxLXCInventory{Containers: []agentshost.ProxmoxLXCContainer{{
+ VMID: 100,
+ Name: "web",
+ Disks: []agentshost.Disk{
+ {
+ Device: "local-lvm:vm-100-disk-0",
+ Mountpoint: "/",
+ Type: "rootfs",
+ TotalBytes: 8 << 30,
+ UsedBytes: 2 << 30,
+ FreeBytes: 6 << 30,
+ Usage: 99,
+ },
+ {
+ Device: "tank:subvol-100-disk-0",
+ Mountpoint: "/srv/data",
+ Type: "mp0",
+ TotalBytes: 1 << 40,
+ UsedBytes: 512 << 30,
+ FreeBytes: 512 << 30,
+ },
+ {
+ Device: "invalid",
+ Mountpoint: "/srv/../etc",
+ Type: "mp1",
+ TotalBytes: 1,
+ },
+ },
+ }}},
+ now,
+ 30,
+ )
+
+ container := models.Container{
+ VMID: 100,
+ Name: "web",
+ Status: "running",
+ Disk: models.Disk{Total: 8 << 30, Used: 1 << 30, Mountpoint: "/"},
+ }
+ monitor.enrichContainerWithAgentLXCFilesystems("pve-a", "node-a", &container, now.Add(time.Minute))
+ if len(container.Disks) != 2 {
+ t.Fatalf("agent LXC disks = %+v", container.Disks)
+ }
+ if container.Disk.Used != 2<<30 || container.Disk.Usage != 25 {
+ t.Fatalf("agent root disk = %+v", container.Disk)
+ }
+ if container.Disks[1].Mountpoint != "/srv/data" || container.Disks[1].Type != "mp0" {
+ t.Fatalf("agent mount disk = %+v", container.Disks[1])
+ }
+
+ for _, test := range []struct {
+ name string
+ instance string
+ node string
+ guestName string
+ status string
+ }{
+ {name: "wrong instance", instance: "pve-b", node: "node-a", guestName: "web", status: "running"},
+ {name: "wrong node", instance: "pve-a", node: "node-b", guestName: "web", status: "running"},
+ {name: "renamed guest", instance: "pve-a", node: "node-a", guestName: "web-new", status: "running"},
+ {name: "stopped guest", instance: "pve-a", node: "node-a", guestName: "web", status: "stopped"},
+ } {
+ t.Run(test.name, func(t *testing.T) {
+ candidate := models.Container{
+ VMID: 100,
+ Name: test.guestName,
+ Status: test.status,
+ Disk: models.Disk{Used: 1},
+ }
+ monitor.enrichContainerWithAgentLXCFilesystems(
+ test.instance,
+ test.node,
+ &candidate,
+ now.Add(time.Minute),
+ )
+ if len(candidate.Disks) != 0 || candidate.Disk.Used != 1 {
+ t.Fatalf("unmatched guest was enriched: %+v", candidate)
+ }
+ })
+ }
+
+ monitor.clearAgentLXCFilesystems("agent-a")
+ unlinked := models.Container{
+ VMID: 100,
+ Name: "web",
+ Status: "running",
+ Disk: models.Disk{Used: 1},
+ }
+ monitor.enrichContainerWithAgentLXCFilesystems(
+ "pve-a",
+ "node-a",
+ &unlinked,
+ now.Add(time.Minute),
+ )
+ if len(unlinked.Disks) != 0 || unlinked.Disk.Used != 1 {
+ t.Fatalf("removed agent cache was applied: %+v", unlinked)
+ }
+}
+
+func TestAgentLXCFilesystemsExpireAndRejectAmbiguousNodeLink(t *testing.T) {
+ now := time.Date(2026, 7, 30, 21, 0, 0, 0, time.UTC)
+ inventory := &agentshost.ProxmoxLXCInventory{Containers: []agentshost.ProxmoxLXCContainer{{
+ VMID: 100,
+ Name: "web",
+ Disks: []agentshost.Disk{{
+ Device: "local-lvm:vm-100-disk-0",
+ Mountpoint: "/",
+ Type: "rootfs",
+ TotalBytes: 8 << 30,
+ UsedBytes: 2 << 30,
+ FreeBytes: 6 << 30,
+ }},
+ }}}
+
+ ambiguousState := models.NewState()
+ ambiguousState.UpdateNodes([]models.Node{
+ {ID: "duplicate", Name: "node-a", Instance: "pve-a"},
+ {ID: "duplicate", Name: "node-b", Instance: "pve-b"},
+ })
+ ambiguousMonitor := &Monitor{state: ambiguousState}
+ ambiguousMonitor.applyAgentLXCFilesystems("duplicate", "agent-a", inventory, now, 30)
+ if len(ambiguousMonitor.proxmoxLXCFilesystemsCache) != 0 {
+ t.Fatalf("ambiguous node link was admitted: %+v", ambiguousMonitor.proxmoxLXCFilesystemsCache)
+ }
+
+ state := models.NewState()
+ state.UpdateNodes([]models.Node{{
+ ID: "node-id",
+ Name: "node-a",
+ Instance: "pve-a",
+ LinkedAgentID: "agent-a",
+ }})
+ monitor := &Monitor{state: state}
+ monitor.applyAgentLXCFilesystems("node-id", "agent-a", inventory, now, 30)
+ container := models.Container{
+ VMID: 100,
+ Name: "web",
+ Status: "running",
+ Disk: models.Disk{Used: 1},
+ }
+ monitor.enrichContainerWithAgentLXCFilesystems(
+ "pve-a",
+ "node-a",
+ &container,
+ now.Add(agentLXCFilesystemMinTTL),
+ )
+ if len(container.Disks) != 0 || container.Disk.Used != 1 {
+ t.Fatalf("expired cache enriched guest: %+v", container)
+ }
+ if len(monitor.proxmoxLXCFilesystemsCache) != 0 {
+ t.Fatalf("expired cache entry was not removed: %+v", monitor.proxmoxLXCFilesystemsCache)
+ }
+
+ monitor.proxmoxLXCFilesystemsCache["expired-elsewhere"] = agentLXCFilesystemCacheEntry{
+ name: "old",
+ expiresAt: now,
+ }
+ monitor.applyAgentLXCFilesystems(
+ "node-id",
+ "agent-a",
+ &agentshost.ProxmoxLXCInventory{},
+ now.Add(time.Second),
+ 30,
+ )
+ if len(monitor.proxmoxLXCFilesystemsCache) != 0 {
+ t.Fatalf("accepted empty inventory did not prune expired entries: %+v", monitor.proxmoxLXCFilesystemsCache)
+ }
+}
diff --git a/internal/monitoring/monitor_polling_containers.go b/internal/monitoring/monitor_polling_containers.go
index d97cd72a81..471fb52d4c 100644
--- a/internal/monitoring/monitor_polling_containers.go
+++ b/internal/monitoring/monitor_polling_containers.go
@@ -262,6 +262,12 @@ func (m *Monitor) collectContainersWithNodes(ctx context.Context, instanceName s
&modelContainer,
statusSnapshot,
)
+ m.enrichContainerWithAgentLXCFilesystems(
+ instanceName,
+ n.Node,
+ &modelContainer,
+ sampleTime,
+ )
// Zero out metrics for non-running containers
if container.Status != "running" {
diff --git a/pkg/agents/host/report.go b/pkg/agents/host/report.go
index 107f05d937..3f8443baa7 100644
--- a/pkg/agents/host/report.go
+++ b/pkg/agents/host/report.go
@@ -55,6 +55,7 @@ type Report struct {
Ceph *CephCluster `json:"ceph,omitempty"`
Libvirt *LibvirtInventory `json:"libvirt,omitempty"`
XCPNG *XCPNGInventory `json:"xcpng,omitempty"`
+ ProxmoxLXC *ProxmoxLXCInventory `json:"proxmoxLxc,omitempty"`
ClusterSensors []ClusterNodeSensors `json:"clusterSensors,omitempty"`
// AvailabilityResults carries availability checks the agent executed on
// behalf of the server for targets assigned to it. The server owns failure
@@ -112,6 +113,23 @@ type XCPNGVM struct {
ResidentHostUUID string `json:"residentHostUuid,omitempty"`
}
+// ProxmoxLXCInventory is the bounded, node-local filesystem inventory
+// collected through the pct CLI on a Proxmox VE host. Only containers the
+// preceding pct list reported running are queried.
+type ProxmoxLXCInventory struct {
+ Containers []ProxmoxLXCContainer `json:"containers"`
+ CollectedAt time.Time `json:"collectedAt"`
+}
+
+// ProxmoxLXCContainer contains direct pct df readings for one local running
+// container. VMID and name are both carried so the server can fail closed
+// when correlating the node-local observation with API inventory.
+type ProxmoxLXCContainer struct {
+ VMID int `json:"vmid"`
+ Name string `json:"name"`
+ Disks []Disk `json:"disks"`
+}
+
// AvailabilityProbeResult is one completed availability check reported by a
// remote probe agent. Outcome mirrors the shared probe vocabulary
// ("reachable", "unreachable", "indeterminate"); anything else is treated as
diff --git a/pkg/agents/host/report_test.go b/pkg/agents/host/report_test.go
index 57b61b1130..a97254618c 100644
--- a/pkg/agents/host/report_test.go
+++ b/pkg/agents/host/report_test.go
@@ -720,3 +720,46 @@ func TestReportXCPNGInventoryJSONRoundTrip(t *testing.T) {
t.Fatalf("XCP-ng inventory = %+v", decoded.XCPNG)
}
}
+
+func TestReportProxmoxLXCInventoryJSONRoundTrip(t *testing.T) {
+ collectedAt := time.Date(2026, 7, 30, 20, 30, 0, 0, time.UTC)
+ report := Report{ProxmoxLXC: &ProxmoxLXCInventory{
+ CollectedAt: collectedAt,
+ Containers: []ProxmoxLXCContainer{{
+ VMID: 200,
+ Name: "app",
+ Disks: []Disk{{
+ Device: "local:subvol-200-disk-0",
+ Mountpoint: "/",
+ Type: "rootfs",
+ TotalBytes: 20 << 30,
+ UsedBytes: 5 << 30,
+ FreeBytes: 15 << 30,
+ Usage: 25,
+ }},
+ }},
+ }}
+ data, err := json.Marshal(report)
+ if err != nil {
+ t.Fatalf("marshal report: %v", err)
+ }
+ var decoded Report
+ if err := json.Unmarshal(data, &decoded); err != nil {
+ t.Fatalf("unmarshal report: %v", err)
+ }
+ if decoded.ProxmoxLXC == nil ||
+ !decoded.ProxmoxLXC.CollectedAt.Equal(collectedAt) ||
+ len(decoded.ProxmoxLXC.Containers) != 1 ||
+ decoded.ProxmoxLXC.Containers[0].VMID != 200 ||
+ decoded.ProxmoxLXC.Containers[0].Disks[0].Mountpoint != "/" {
+ t.Fatalf("Proxmox LXC inventory = %+v", decoded.ProxmoxLXC)
+ }
+
+ bare, err := json.Marshal(Report{})
+ if err != nil {
+ t.Fatalf("marshal bare report: %v", err)
+ }
+ if contains(string(bare), "proxmoxLxc") {
+ t.Fatalf("nil Proxmox LXC inventory should be omitted: %s", bare)
+ }
+}