Skip to content

[stable35] fix: stop reporting unknown server values as if they were measurements - #1127

Closed
kesselb wants to merge 1 commit into
stable35from
backport/1120/stable35
Closed

kesselb wants to merge 1 commit into
stable35from
backport/1120/stable35

Conversation

@kesselb

@kesselb kesselb commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Manual backport of #1120

Every "not available" figure in this app is -1, and several paths did
arithmetic on that sentinel or formatted it as though it were a reading:

- SystemStatistics scaled it to kB, so the OCS API answered
  mem_total: -1024 to external monitoring tools
- formatBytes() took the absolute value, so PHP's memory_limit = -1
  ("unlimited") rendered as "1.0 B"
- DatabaseStatistics returned the string 'N/A' for a field typed and
  formatted as a number, which reached the page as "NaN B"
- MemoryChartSection and ResourceOverviewSection guarded against an 'N/A'
  string the backend never sends, so -1 charted as a real series on a
  degenerate 0-to-0 axis
- the OS backends claimed a single core when the count was unknown, and
  that 1 became the divisor for the load average: an eight-core host under
  load read as "800 %"

Unknown values are now -1 throughout and render as "Unknown", or are left
out where a percentage cannot be computed. PHP's own "unlimited" sentinels
(memory_limit -1, max_execution_time 0) are labelled as such rather than
formatted as sizes. The load average survives a missing core count: it
comes from sys_getloadavg() and is real even when the count is not.

Read CPU, memory and uptime where /proc is hidden

Debian's and Ubuntu's apache2 unit ships ProcSubset=pid and
ProtectProc=invisible, so the web server sees only its own processes in
/proc. On those hosts -- a large share of installs -- this app has never
been able to report CPU, memory or uptime at all, and now reports honestly
that it cannot, which is worse to look at than it needs to be.

Commands still run there, so the Linux backend now falls back:

- threads: nproc, which uses sched_getaffinity rather than /proc
- memory: the per-NUMA-node meminfo files under /sys, which ProcSubset
  does not cover, before free(1) -- free reads /proc/meminfo itself and is
  bound to fail wherever that file is hidden, so trying /sys first settles
  which situation we are in without paying for a fork
- uptime: a process that has only just started carries the system uptime
  in its own /proc/<pid>/stat, and a process may always read its own entry

aarch64 and s390x are handled too: they list their processors but carry no
"model name" line, so the count is now taken separately from the name.

Cut the cost of the two-second poll

A poll spends about 1.3 ms collecting data inside a request that costs
hundreds of milliseconds, so the fix is fewer and cheaper requests, not
faster collection:

- useLiveData stops polling while the tab is hidden and polls immediately
  on return, so a page left open in the background no longer fetches
  numbers nobody can see
- getTime() no longer forks date(1) for something PHP can answer; the
  system zone is read from /etc/localtime because Nextcloud runs on UTC
- LiveData no longer calls getCPU() -- which parses /proc/cpuinfo, or forks
  nproc -- only to reach sys_getloadavg(), which uses none of it
- the sampled uptime is cached as a boot time and re-measured once a
  minute rather than once per poll

Together these leave the poll forking less than it did before: hosts with a
readable /proc now fork nothing at all, where every host used to fork date.

Signed-off-by: Frank Karlitschek <frank.karlitschek@nextcloud.com>
Assisted-by: Claude Code:claude-opus-5
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
@kesselb
kesselb changed the base branch from master to stable35 September 9, 2026 17:42
@kesselb kesselb changed the title Backport/1120/stable35 [stable35] fix: stop reporting unknown server values as if they were measurements Sep 9, 2026
@kesselb
kesselb enabled auto-merge September 9, 2026 17:43
@kesselb kesselb added this to the Nextcloud 35 milestone Sep 9, 2026
@kesselb

kesselb commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

Merged via #1126

@kesselb kesselb closed this Sep 9, 2026
auto-merge was automatically disabled September 9, 2026 17:54

Pull request was closed

@kesselb
kesselb deleted the backport/1120/stable35 branch September 9, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants