Skip to content

feat: add hardware server info - #79

Merged
loadinglucian merged 6 commits into
mainfrom
feat/hardware-server-info
Nov 10, 2025
Merged

feat: add hardware server info#79
loadinglucian merged 6 commits into
mainfrom
feat/hardware-server-info

Conversation

@loadinglucian

@loadinglucian loadinglucian commented Nov 10, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Server info now shows a dedicated "Hardware" section when available, listing CPU cores (singular/plural handled), RAM in GB or MB, and disk type (uppercased) alongside existing cataloged metrics.
  • Chores

    • Added hardware detection and improved environment/tool checks to ensure consistent hardware reporting in the final server info output.

@coderabbitai

coderabbitai Bot commented Nov 10, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds hardware detection and reporting: the shell playbook now detects cpu_cores, ram_mb, and disk_type and emits them in the YAML output; the PHP ServersTrait renders a new "Hardware" block when that data exists. ensure_tools() now ensures ss and lsblk are available.

Changes

Cohort / File(s) Summary
PHP Server Trait
app/Traits/ServersTrait.php
Adds conditional rendering of a "Hardware" section in server info output. Builds human-readable entries for cpu_cores (singular/plural), ram_mb (converted to GB or MB), and disk_type (uppercased) when a hardware array is present; inserted after details and before services.
Bash Playbook — Hardware Detection & Output
playbooks/server-info.sh
Adds detect_cpu_cores(), detect_ram_mb(), and detect_disk_type() helpers with fallbacks; collects hardware metrics and emits them under a hardware block in the final YAML payload.
Bash Playbook — Tools & Packaging
playbooks/server-info.sh
Extends ensure_tools() to require ss and lsblk; updates package installation to include/ensure util-linux (for lsblk) alongside iproute2 / iproute per distro family.

Sequence Diagram(s)

sequenceDiagram
  participant Playbook as server-info.sh
  participant Target as Remote Server
  participant PHP as ServersTrait
  participant User as CLI/UI

  rect `#E8F5E9`
    Playbook->>Target: detect_cpu_cores()
    Playbook->>Target: detect_ram_mb()
    Playbook->>Target: detect_disk_type()
    Target-->>Playbook: { cpu_cores, ram_mb, disk_type }
  end

  rect `#E3F2FD`
    Playbook->>Playbook: assemble YAML payload (includes hardware)
    Playbook-->>PHP: send YAML payload
  end

  rect `#FFF3E0`
    PHP->>PHP: parse payload
    alt hardware present
      PHP->>PHP: render "Hardware" block
    end
    PHP-->>User: display server info (with Hardware)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect detection helper fallbacks and platform-specific parsing in playbooks/server-info.sh.
  • Verify YAML emission format and PHP parsing for absent/partial hardware fields in app/Traits/ServersTrait.php.
  • Confirm ensure_tools() package installation logic and lsblk/ss availability across distro families.

Possibly related PRs

  • bigpixelrocket/deployer-php#77 — modifies the same app/Traits/ServersTrait.php and playbooks/server-info.sh for server-info metrics/display changes.
  • bigpixelrocket/deployer-php#62 — prior changes to server-info tooling and reporting that overlap with hardware reporting.

Poem

🐇 I counted cores beneath moonbeam light,

Measured RAM in gig and byte,
Disks declared their TYPE in caps,
A tiny Hardware block perhaps,
Hops of code — a rabbit’s delight.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add hardware server info' clearly and concisely describes the main change: adding hardware information to server details, which is fully reflected in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/hardware-server-info

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
playbooks/server-info.sh (1)

182-202: Disk type detection works well for common scenarios.

The implementation correctly detects SSD vs HDD using TRIM support (discard granularity) as the primary method and rotation flag as fallback. This approach works reliably for cloud VMs and physical servers with standard disk naming (sda/vda).

Optional: Consider adding NVMe detection.

The current regex ^[sv]da doesn't match NVMe drives (nvme0n1). While NVMe is less common in typical deployment scenarios, you could extend support:

-	disc_gran=$(lsblk -d -o name,disc-gran 2> /dev/null | grep -E "^[sv]da" | head -n1 | awk '{print $2}')
+	disc_gran=$(lsblk -d -o name,disc-gran 2> /dev/null | grep -E "^([sv]da|nvme)" | head -n1 | awk '{print $2}')

And similarly for the rotation check on line 196.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11a9edb and e827587.

📒 Files selected for processing (2)
  • app/Traits/ServersTrait.php (1 hunks)
  • playbooks/server-info.sh (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.php

📄 CodeRabbit inference engine (.cursor/rules/00-main.mdc)

**/*.php: Eliminate single-use methods: inline if a method is called only once
Cache computed values: initialize expensive calculations in the constructor
Avoid method call overhead: prefer direct property access when appropriate

Files:

  • app/Traits/ServersTrait.php
🔇 Additional comments (6)
app/Traits/ServersTrait.php (1)

147-178: LGTM!

The hardware display logic is well-structured and defensive. It correctly handles mixed types for hardware values, provides clear formatting (GB vs MB, singular vs plural cores), and only displays the section when data is available.

playbooks/server-info.sh (5)

146-157: LGTM!

The tool installation logic correctly adds util-linux (which provides lsblk) to the package list for hardware detection. The check on line 147 now verifies both ss and lsblk are available before skipping installation.


168-170: LGTM!

The CPU core detection uses nproc with a sensible fallback to "1".


175-177: LGTM!

The RAM detection correctly uses free -m to get total memory in MB with a reasonable fallback.


377-377: LGTM!

The hardware detection is properly integrated into the main execution flow with appropriate variable declarations and user feedback messages.

Also applies to: 389-393


425-428: LGTM!

The hardware section is correctly formatted as valid YAML with proper indentation and uses the variables populated by the detection functions.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
playbooks/server-info.sh (1)

146-159: Ensure tools are available before they're used in hardware detection.

Hardware detection functions detect_cpu_cores() and detect_disk_type() (lines 389–392) invoke nproc and lsblk respectively, but ensure_tools() is called afterward at line 395. If these tools are not already present, the detection will silently fall back to defaults ("1" for cores, "hdd" for disk type) before the installation attempt.

While most modern systems have these tools pre-installed (triggering the early return at line 147), the logic ordering is backwards. Reorder ensure_tools() to be called immediately after permission checks and before hardware detection.

 	echo "✓ Checking permissions..."
 	permissions=$(check_permissions)
 
+	echo "✓ Cataloging services..."
+	ensure_tools "$family" "$permissions"
+
 	echo "✓ Detecting hardware..."
 	cpu_cores=$(detect_cpu_cores)
 	ram_mb=$(detect_ram_mb)
 	disk_type=$(detect_disk_type)
 
-	echo "✓ Cataloging services..."
-	ensure_tools "$family" "$permissions"
 
 	echo "✓ Checking Caddy status..."
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e827587 and d7cc476.

📒 Files selected for processing (1)
  • playbooks/server-info.sh (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
playbooks/server-info.sh (2)
playbooks/demo-site.sh (1)
  • run_cmd (37-43)
playbooks/server-install.sh (1)
  • run_cmd (49-55)
🔇 Additional comments (2)
playbooks/server-info.sh (2)

168-202: Conservative hardware detection with safe fallbacks.

The three new detection functions handle missing tools gracefully:

  • detect_cpu_cores() falls back to "1"
  • detect_ram_mb() falls back to "512"
  • detect_disk_type() uses two methods (disc-gran → rotation flag → "hdd" fallback)

The pattern matching in detect_disk_type() (lines 187, 196) targets common primary disk names (^([sv]da|nvme)), which covers standard Linux scenarios. Secondary devices or unusual setups would gracefully default to "hdd".


425-428: Verify YAML hardware section is rendered correctly by ServersTrait.

The new hardware section follows proper YAML nesting and includes three fields. Ensure the PHP ServersTrait (mentioned in the AI summary but not provided) correctly parses and displays this structure, particularly handling the case where values may be placeholder defaults from fallbacks.

If you have the PHP ServersTrait available, verify it correctly renders:

  • cpu_cores as an integer (with proper singular/plural handling if displaying as text)
  • ram_mb as an integer or converted to GB when appropriate
  • disk_type as uppercase ("SSD" or "HDD")

Reorder ensure_tools() execution before detect_disk_type() to prevent
silent fallback to incorrect 'hdd' default when lsblk is not available.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
playbooks/server-info.sh (2)

1-16: Update file header documentation to include hardware detection.

The docstring describes the script's outputs but omits hardware metrics. Update line 5 and the "Returns YAML with" section (lines 10-16) to reflect the new hardware block with cpu_cores, ram_mb, and disk_type.

Apply this diff:

 # Gather Server Information
 # ----
-# This playbook detects distribution, family, permissions, listening services, Caddy metrics, and PHP-FPM metrics.
+# This playbook detects distribution, family, permissions, hardware info, listening services, Caddy metrics, and PHP-FPM metrics.
 #
 # Required Environment Variables:
 #   DEPLOYER_OUTPUT_FILE - Output file path (provided automatically)
 #
 # Returns YAML with:
 #   - distro: ubuntu|debian|fedora|centos|rocky|alma|rhel|amazon|unknown
 #   - family: debian|fedora|redhat|amazon|unknown
 #   - permissions: root|sudo|none
+#   - hardware: cpu_cores, ram_mb, disk_type
 #   - caddy: Caddy metrics (available, version, sites_count, domains, uptime_seconds, active_requests, total_requests, memory_mb)
 #   - php_fpm: PHP-FPM metrics (available, pool, process_manager, uptime_seconds, accepted_conn, listen_queue, idle_processes, active_processes, total_processes, max_children_reached, slow_requests)
 #   - ports: map of port numbers to process names

182-202: Disk detection regex pattern may miss some disk types.

The grep pattern ^([sv]da|nvme) on lines 187 and 196 matches only sda, vda, and nvme—it would skip sdb, sdc, vdb, vdc, etc. While this is unlikely in practice (first disk is typically sda or nvme0n1), the function would default to "hdd" in those cases.

Consider making the pattern more permissive to cover all virtio and SATA disks.

Apply this diff to match all disk types more reliably:

-	disc_gran=$(lsblk -d -o name,disc-gran 2> /dev/null | grep -E "^([sv]da|nvme)" | head -n1 | awk '{print $2}')
+	disc_gran=$(lsblk -d -o name,disc-gran 2> /dev/null | grep -E "^([sv]d|nvme)" | head -n1 | awk '{print $2}')
 
 	# If disc-gran is non-zero (e.g., "512B"), it's an SSD
 	if [[ -n $disc_gran && $disc_gran != "0B" ]]; then
@@ -194,7 +194,7 @@ detect_disk_type() {
 	fi
 
 	# Fallback: Check rotation flag (works for physical disks)
-	rotation=$(lsblk -d -o name,rota 2> /dev/null | grep -E "^([sv]da|nvme)" | head -n1 | awk '{print $2}')
+	rotation=$(lsblk -d -o name,rota 2> /dev/null | grep -E "^([sv]d|nvme)" | head -n1 | awk '{print $2}')
 	if [[ $rotation == "0" ]]; then
 		echo "ssd"
 	else
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7cc476 and 537f00e.

📒 Files selected for processing (1)
  • playbooks/server-info.sh (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
playbooks/server-info.sh (2)
playbooks/demo-site.sh (1)
  • run_cmd (37-43)
playbooks/server-install.sh (1)
  • run_cmd (49-55)
🔇 Additional comments (3)
playbooks/server-info.sh (3)

142-159: Tool installation logic is sound.

The ensure_tools function correctly checks for both ss and lsblk before attempting installation, installs the right packages for each family (iproute2/util-linux on Debian; iproute/util-linux on RedHat), and includes a yum→dnf fallback for newer RHEL/CentOS versions.


168-177: Hardware detection functions have appropriate fallbacks.

detect_cpu_cores() and detect_ram_mb() both use standard tools (nproc, free -m) and include sensible defaults ("1" and "512" respectively), ensuring the script won't fail if these commands behave unexpectedly.


375-428: Hardware detection integration is clean and well-ordered.

Variables are declared upfront (line 377), functions are called after ensure_tools to guarantee lsblk availability (lines 392–395), and YAML output structure is properly indented and consistent with the rest of the file. The hardware block will integrate seamlessly with the existing PHP rendering logic.

Add hardware detection to script description and YAML output documentation.
The playbook now detects cpu_cores, ram_mb, and disk_type.
Change pattern from ^([sv]da|nvme) to ^([sv]d|nvme) to detect all SATA
and virtio disks (sdb, sdc, vdb, vdc, etc.), not just the first disk.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
playbooks/server-info.sh (1)

169-203: Hardware detection logic is sound with appropriate fallbacks.

The three-tier approach (nproc → 1, free -m → 512, TRIM detection → rotation flag → hdd) provides sensible degradation. The TRIM-first detection is cloud-friendly.

One minor note: variable naming uses disc_gran rather than disk_gran. Consider aligning with the function name for consistency.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 537f00e and 5252802.

📒 Files selected for processing (1)
  • playbooks/server-info.sh (6 hunks)
🔇 Additional comments (4)
playbooks/server-info.sh (4)

5-5: Excellent documentation updates.

The header comments clearly document the new hardware detection capability alongside existing distro and service metrics.

Also applies to: 14-14


143-160: Tool installation logic is sound.

The early-return optimization correctly checks for both required tools, and the package installation for each distribution family is accurate. The dnf fallback for RedHat-based distros is a good defensive choice.


378-378: Clean integration into main execution flow.

Variable declarations are scoped appropriately, and hardware detection is called at the right point in the sequence (after tool validation, before service checks).

Also applies to: 393-396


426-429: YAML structure is properly formatted and integrated.

The hardware block is correctly nested with consistent indentation and positioned logically between system metadata and service metrics. Structure aligns with expected downstream consumption by the PHP trait.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
playbooks/server-info.sh (1)

169-171: Minor: CPU core detection fallback is conservative.

Using nproc with fallback to "1" is safe, but falling back to a single core on error could misrepresent a multi-core system. Consider whether "1" is the best default, or if logging/warning would be helpful. This is acceptable as-is but worth noting.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5252802 and 14ef900.

📒 Files selected for processing (1)
  • playbooks/server-info.sh (6 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
playbooks/server-info.sh (2)
playbooks/demo-site.sh (1)
  • run_cmd (37-43)
playbooks/server-install.sh (1)
  • run_cmd (49-55)
🔇 Additional comments (6)
playbooks/server-info.sh (6)

5-5: Documentation updates are clear and accurate. Includes hardware detection in overview and output schema.

Also applies to: 14-14


378-378: Hardware detection integration in main() is well-structured.

Variables are properly scoped and detection functions are called in the correct sequence (after ensure_tools()). The progress messages are helpful for debugging.

Also applies to: 393-396


426-429: YAML hardware block structure is clean and well-positioned.

Proper indentation and placement. Since all hardware detection functions have fallback defaults (e.g., "1" for cores, "512" for RAM, "hdd" for disk type), the values should always be populated.


176-178: I'll search for information about the free command output format stability across util-linux versions, then check the codebase for any version or distro support constraints.

Let me check the codebase to understand the context and purpose of this function:

Let me check the codebase context for this function:

Based on my verification, the Mem: line format in free -m output shows columns for total, used, free, shared, buff/cache, and available. The output format differs between RHEL 6 and RHEL 7/8, but key parameters remain consistent.

The code free -m 2> /dev/null | awk 'NR==2 {print $2}' extracts:

  • NR==2: The second line (the Mem: line)
  • $2: The total RAM column (first numeric value after the "Mem:" label)

This field position is stable across all documented util-linux versions. However, parsing the output of free is not totally reliable, and reading values from /proc/meminfo is an alternative with a format that is somewhat easier to parse and should be stable.

The code's fallback (|| echo "512") provides basic resilience. The implementation works correctly across supported distros, though consider these minor caveats:

  • Localization (LC_ALL) could theoretically affect output
  • Very old systems might behave differently
  • /proc/meminfo would be a more robust alternative

No critical compatibility issues found; the current implementation is functional.


147-160: Package names verified—code is correct.

The verify confirms that the package selection is accurate across all distributions:

  • Debian/Ubuntu correctly uses iproute2 (provides ss) and util-linux (provides lsblk)
  • Fedora/RHEL/CentOS correctly uses iproute (provides ss) and util-linux (provides lsblk)

The code's distro-specific package selection is appropriate. No changes needed.


183-203: Disk type detection scope is cloud-VM focused; confirm if environment coverage is complete.

The function is explicitly designed for "virtualized environments (cloud VMs)" per the comment at line 186. In this scope, the regex ^([sv]d|nvme) is reasonably appropriate:

  • Covered: sd* (cloud provider disks), vd* (QEMU/KVM virtio), nvme (instance storage)
  • Gaps exist: xvd* (Xen/Citrix hypervisors), mmcblk* (embedded/ARM)

However, one clarification on the review comment: it mentions vd may be missed, but vd is matched by the [sv]d pattern.

Action: Confirm whether your deployment environment includes Xen-based or other hypervisors beyond cloud providers. If so, expand the regex to include xvd* and any other device prefixes in your target environments. Otherwise, the current scope is appropriate.

@loadinglucian
loadinglucian merged commit 2ba08b4 into main Nov 10, 2025
5 checks passed
@loadinglucian
loadinglucian deleted the feat/hardware-server-info branch November 10, 2025 20:07
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.

1 participant