Skip to content

Add CPU and MEM to the advanced view mode#73

Merged
mstrhakr merged 25 commits intodevfrom
mstrhakr/issue72
Mar 30, 2026
Merged

Add CPU and MEM to the advanced view mode#73
mstrhakr merged 25 commits intodevfrom
mstrhakr/issue72

Conversation

@mstrhakr
Copy link
Copy Markdown
Owner

What changed

Added real-time CPU and memory usage display to the advanced view mode for both individual containers and aggregate stack totals — matching the existing Docker manager tab's load display.

Implementation:

  • Subscribe to the existing dockerload Nchan WebSocket channel (/sub/dockerload) which streams docker stats data as shortID;CPU%;MemUsage per line
  • CPU values are normalized by total thread count (using cpu_list() from Helpers.php, with nproc fallback) to show per-system percentages consistent with the Docker tab
  • Stack-level aggregates are computed by summing CPU/memory across all member containers, using data-ctids baked into each stack row at render time so aggregation works immediately — no need to expand the stack first
  • Stopped stacks and containers show a - placeholder instead of misleading 0% / 0B since they never receive stats data
  • Added Nchan="docker_load" header to Compose.page so the docker_load daemon starts when using the standalone Tasks menu entry (Docker tab already provides it when embedded)

Files changed:

  • compose_manager_main.php — PHP $cpuCount calculation, CSS for usage bars, parseMemToBytes()/formatBytes() JS helpers, NchanSubscriber message handler with per-container updates and per-stack aggregation, CPU/MEM column in container detail tables
  • compose_list.php — Collects container short IDs into data-ctids attribute on stack rows, adds CPU/MEM column cell to stack table, updates colspans 9→10
  • comboButton.css — Column width adjustments for container detail table to fit the new CPU & Memory column
  • Compose.page — Added Nchan="docker_load" header
  • util.php — Added $skipDocker parameter to allFromRoot() for skeleton rendering without docker ps calls

Related issues
Closes #72

Checklist

  • I have added/updated tests where applicable
  • I have updated documentation (docs/, README, or plugin docs)
  • Linted/formatted the code
  • Verified on Unraid or CI

Testing notes

  1. Open the Docker → Compose tab in advanced view mode — each running stack should show aggregate CPU% and memory with a thin usage bar
  2. Expand a stack — individual containers should show their own CPU% and memory (format: used / limit from docker stats)
  3. Stopped stacks should display - in the load column, not 0%
  4. Open the standalone Compose page (Tasks → Docker Compose) — load data should still appear since Nchan="docker_load" is now set
  5. Start/stop a stack — after the list reloads, data-ctids and display should update correctly

Notes
No migration steps or backward compatibility issues. The feature is purely additive and only visible in advanced view mode (cm-advanced CSS class). The Nchan subscription gracefully degrades — if NchanSubscriber is not available, the load column simply stays at its placeholder value.

mstrhakr added 11 commits March 29, 2026 14:25
- Add missing 'var loadMap = {}' declaration
- Fix cpuRaw used before declaration (moved above cpuNorm)
- Remove duplicate cpuNorm/loadMap assignments and orphan braces
- Add parts.length >= 3 guard to skip malformed rows
- Use Math.max(composeCpuCount, 1) to prevent division by zero
The .ct-col-icon class is defined in CSS but never used in any HTML
output. Container detail tables have no icon column.
Stopped stacks and containers will never receive docker stats data,
so showing '0%' / '0B' is misleading. Show '-' instead and hide the
usage bar and memory span for non-running entries.
Copilot AI review requested due to automatic review settings March 29, 2026 20:24
@mstrhakr mstrhakr self-assigned this Mar 29, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds real-time CPU and memory load reporting to the Compose Manager advanced view (per-container and per-stack aggregate) by subscribing to the existing dockerload Nchan channel, and improves context-menu usability via right-click support.

Changes:

  • Display live CPU% (normalized) and memory usage for containers and stack totals in advanced view, including new table columns and usage bars.
  • Add data-ctids to stack rows to enable stack-level aggregation immediately (without expanding details).
  • Improve UX by enabling right-click context menus on stack/container rows and ensure standalone Compose page starts the docker_load Nchan daemon.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
source/compose.manager/styles/comboButton.css Adjusts container details table column widths and adds a new load column width.
source/compose.manager/php/util.php Adds $skipDocker option to StackInfo::allFromRoot() for faster stack enumeration without Docker preloading.
source/compose.manager/php/compose_manager_main.php Implements dockerload subscription + UI updates/aggregation; adds CPU/MEM column and related styling; adds right-click context-menu behavior.
source/compose.manager/php/compose_list.php Embeds container short IDs (data-ctids) and renders the new CPU/MEM stack column; updates colspans.
source/compose.manager/compose.manager.dashboard.page Adds right-click behavior to open dashboard context menus from row clicks.
source/compose.manager/Compose.page Adds Nchan="docker_load" so load metrics work from the standalone menu entry.
deploy.ps1 Extends deploy script to support multiple remote hosts and build-only behavior when no host is provided.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +21 to +24
// CPU count for load normalization (matches Docker manager's cpu_list approach)
$cpus = function_exists('cpu_list') ? cpu_list() : [];
$cpuCount = (!empty($cpus) && isset($cpus[0]))
? count($cpus) * count(preg_split('/[,-]/', $cpus[0]))
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

The $cpuCount calculation will undercount threads if cpu_list() returns CPU ranges (e.g. "0-7" or "0-3,8-11"); preg_split('/[,-]/', ...) counts endpoints, not CPUs. Consider parsing comma-separated lists with range expansion (or using a single authoritative helper used by the Docker tab) so CPU% normalization stays accurate across all cpu_list formats.

Suggested change
// CPU count for load normalization (matches Docker manager's cpu_list approach)
$cpus = function_exists('cpu_list') ? cpu_list() : [];
$cpuCount = (!empty($cpus) && isset($cpus[0]))
? count($cpus) * count(preg_split('/[,-]/', $cpus[0]))
/**
* Count CPUs in a CPU list/range spec (e.g. "0-3,8-11" => 8).
* Mirrors the range semantics used by the Docker manager's cpu_list helper.
*/
function compose_manager_cpu_spec_count($cpuSpec)
{
$cpuSpec = trim((string)$cpuSpec);
if ($cpuSpec === '') {
return 0;
}
$segments = explode(',', $cpuSpec);
$count = 0;
foreach ($segments as $segment) {
$segment = trim($segment);
if ($segment === '') {
continue;
}
if (strpos($segment, '-') !== false) {
list($start, $end) = explode('-', $segment, 2);
$start = (int)$start;
$end = (int)$end;
if ($end < $start) {
$tmp = $start;
$start = $end;
$end = $tmp;
}
$count += max(0, $end - $start + 1);
} else {
// Single CPU index
$count += 1;
}
}
return $count;
}
// CPU count for load normalization (matches Docker manager's cpu_list approach)
$cpus = function_exists('cpu_list') ? cpu_list() : [];
$cpuCount = (!empty($cpus) && isset($cpus[0]))
? count($cpus) * compose_manager_cpu_spec_count($cpus[0])

Copilot uses AI. Check for mistakes.
@mstrhakr mstrhakr changed the title Update context menus and enhance load metrics display Add right click context menus and add CPU and MEM to the advanced view mode Mar 29, 2026
@mstrhakr mstrhakr changed the title Add right click context menus and add CPU and MEM to the advanced view mode Add CPU and MEM to the advanced view mode Mar 29, 2026
@mstrhakr mstrhakr merged commit 5bf4a89 into dev Mar 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants