mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6920] [MERGED] fix(monitoring): use container sources for LXC CPU, swap and uptime #6523
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6523
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6920
Author: @Vaso73
Created: 10/24/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei
Base:
main← Head:fix/lxc-container-metrics📝 Commits (10+)
52a2c2afix(monitoring): use container sources for LXC CPU, swap and uptime85c1634docs(monitoring): add synthetic LXC metrics screenshots7ca4dcfstyle(monitoring): format LXC metric regression fixtures5867aacfix(monitoring): retain metric availability in nodes and botsaec5e11fix(monitoring): wait for status before seeding overview history497c225Merge remote-tracking branch 'origin/main' into pr/692085cf483chore(monitoring): drop the unreferenced screenshots and README sectionb2be24dtest(monitoring): fold the metric availability tests into the existing files536e1befix(nodes): show an unprobed node's uptime as a dash againb044f19style(monitoring): drop the blank lines closing the host status blocks📊 Changes
34 files changed (+1706 additions, -127 deletions)
View changed files
📝
docs/public/openapi.json(+34 -0)📝
frontend/public/openapi.json(+34 -0)📝
frontend/src/generated/examples.ts(+9 -0)📝
frontend/src/generated/schemas.ts(+19 -0)📝
frontend/src/generated/types.ts(+3 -0)📝
frontend/src/generated/zod.ts(+3 -0)📝
frontend/src/models/status.ts(+11 -1)➕
frontend/src/pages/index/ContainerMetrics.stories.tsx(+67 -0)📝
frontend/src/pages/index/IndexPage.tsx(+7 -1)📝
frontend/src/pages/index/SystemStrip.tsx(+6 -2)📝
frontend/src/pages/index/VitalTile.tsx(+7 -5)📝
frontend/src/pages/index/useOverviewHistory.ts(+35 -7)📝
frontend/src/pages/nodes/NodeList.tsx(+17 -6)📝
frontend/src/schemas/node.ts(+2 -0)📝
frontend/src/schemas/status.ts(+2 -0)➕
frontend/src/test/container-history.test.tsx(+186 -0)➕
frontend/src/test/container-metrics.test.ts(+39 -0)➕
frontend/src/test/node-metrics-availability.test.tsx(+73 -0)📝
internal/database/model/model.go(+5 -3)➕
internal/util/sys/lxc_metrics.go(+10 -0)...and 14 more files
📄 Description
Summary
Use verified container sources for CPU, swap and uptime on Linux LXC installations with LXCFS. Show unavailable samples as
—and keep corrected CPU/swap history separate from earlier host values. Preserve unavailable-metric flags in node heartbeats, API responses and bot reports, and wait for the first valid status before loading Overview history.Why
The existing dashboard can combine container RAM with host swap, host uptime and physical CPU topology. A synthetic container with 512 MiB of swap and 52,624 seconds of uptime reproduces the discrepancy against the current upstream because the swap and uptime helpers bypass LXCFS.
Swap and uptime now come from their verified LXCFS mounts. CPU uses the whole-container cgroup v2 usage delta, normalized by the visible LXCFS CPU count and capped by any readable CPU quota. The cgroup mount root and container init membership must be verified before using that counter. First samples, counter/capacity resets and unverifiable sources are unavailable rather than measured zeroes.
Optional
resourceScopeandunavailableMetricsresponse fields apply to CPU, swap and uptime only. Existing fields remain compatible. Native and non-Linux paths and all RAM/load/disk/network implementations are retained. This targets LXCFS with a unified cgroup v2 root; general Docker, cgroup v1 and limits hidden outside the namespace are outside its scope.Node probes retain
unavailableMetricsthrough heartbeat storage and the node read API. Unavailable CPU samples are excluded from node history; the node list, mobile details and Telegram/Discord uptime reports display—. Measured zero and older node responses without availability metadata retain their existing meaning.Overview history is loaded after the first valid status establishes its resource scope. Temporary status errors do not prepend the same history again, and cancelled responses from an earlier scope are ignored.
Type of change
Areas affected
How was this tested?
go test -shuffle=on -count=1 -p 2 ./...passed.go test -race -shuffle=on -count=1 ./internal/util/sys ./internal/web/servicepassed. The node/Telegram/Discord follow-up also passed race tests across all three affected service packages; a local Go build passed.de21c128passed the affected node/Telegram/Discord package tests, UI regressions, frontend static checks and generated-contract consistency.Screenshots / recordings
All images show the built Overview page with synthetic API fixtures.
Measured container values
Unavailable CPU, swap and uptime
Mobile layout at 390 px
Breaking changes
No breaking API or configuration changes. The normal database migration adds a nullable
nodes.unavailable_metricscolumn so availability survives refreshes and restarts. Legacy rows and older node responses without metadata remain compatible, and existing numeric response fields keep their types. Existing host history is retained, with separate CPU/swap series used for the corrected container samples.Checklist
go buildand the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.