Skip to content

fix: use container-aware load averages - #1162

Merged
kesselb merged 1 commit into
nextcloud:masterfrom
jiri001meitner:fix/container-aware-load-average
Oct 11, 2026
Merged

kesselb merged 1 commit into
nextcloud:masterfrom
jiri001meitner:fix/container-aware-load-average

Conversation

@jiri001meitner

Copy link
Copy Markdown
Contributor

Summary

  • read Linux load averages from /proc/loadavg
  • avoid leaking the physical host load into LXC/container metrics
  • retain sys_getloadavg() as a portable fallback when the OS backend cannot provide a value
  • add tests for valid, missing, and malformed /proc/loadavg data

Problem

Inside an LXC container, PHP's sys_getloadavg() can report the physical host load while /proc/loadavg is correctly virtualized for the container. Server Info then divides the host load by the container's CPU count, producing persistent values such as 500% on an otherwise idle 8-vCPU container.

Observed on the affected system:

sys_getloadavg(): 37.91 42.84 49.44
/proc/loadavg:     0.22  0.41  0.41
CPUs:              8

Linux now prefers its namespace-aware procfs value. Non-Linux systems and installations where procfs is unavailable keep the existing PHP fallback.

Validation

  • PHP syntax check passes
  • PHP CS Fixer passes
  • Psalm passes with no errors
  • verified against the affected LXC installation: the Server Info backend and /proc/loadavg now return the same three values
  • unit tests added for valid, unavailable, and invalid procfs data; the complete PHPUnit suite could not be run locally because the packaged Nextcloud installation does not ship the core test framework

AI assistance

This contribution was prepared with assistance from OpenAI Codex (GPT-5). The contributor reviewed, tested, and is responsible for the submitted changes.

@kesselb kesselb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR

Comment thread lib/Os.php Outdated
return sys_getloadavg();
$load = $this->backend->getAverageLoad();

return $load !== false ? $load : sys_getloadavg();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

		if (function_exists('sys_getloadavg')) {
			return sys_getloadavg();
		}
		return false;
  1. Please check if the function is available (e.g. when disabled with disabled_functions).

  2. Please remove getAverageLoad in Cpu.php.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Added function_exists('sys_getloadavg') check for fallback and removed the redundant getAverageLoad method from CPU.php.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@kesselb
kesselb force-pushed the fix/container-aware-load-average branch from 53a5bd3 to f9acf3e Compare October 11, 2026 13:25
@kesselb kesselb changed the title fix(linux): use container-aware load averages fix: use container-aware load average Oct 11, 2026
@kesselb kesselb changed the title fix: use container-aware load average fix: use container-aware load averages Oct 11, 2026
Assisted-by: ClaudeCode:claude-sonnet-5-5
Assisted-by: Codex:gpt-5

Signed-off-by: jiri001meitner <jiri001meitner@gmail.com>
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
@kesselb kesselb added the AI assisted This PR contains AI-assisted commits label Oct 11, 2026
@kesselb
kesselb force-pushed the fix/container-aware-load-average branch from f9acf3e to c42f7e7 Compare October 11, 2026 13:30
@kesselb
kesselb merged commit 1e1ff3a into nextcloud:master Oct 11, 2026
37 of 38 checks passed
@kesselb

kesselb commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

/backport to stable35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants