Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/Traits/ServersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,38 @@ protected function displayServerInfo(array $info): void
$this->io->displayDeets($deets);
$this->io->writeln('');

// Display hardware information if available
if (isset($info['hardware']) && is_array($info['hardware'])) {
$hardwareItems = [];

if (isset($info['hardware']['cpu_cores'])) {
/** @var int|string $cpuCores */
$cpuCores = $info['hardware']['cpu_cores'];
$coresText = $cpuCores === '1' || $cpuCores === 1 ? '1 core' : "{$cpuCores} cores";
$hardwareItems[] = "CPU: {$coresText}";
}

if (isset($info['hardware']['ram_mb'])) {
/** @var int|string $ramMb */
$ramMb = $info['hardware']['ram_mb'];
$ramGb = round((int) $ramMb / 1024, 1);
$ramText = $ramGb >= 1 ? "{$ramGb} GB" : "{$ramMb} MB";
$hardwareItems[] = "RAM: {$ramText}";
}

if (isset($info['hardware']['disk_type'])) {
/** @var string $diskType */
$diskType = $info['hardware']['disk_type'];
$diskText = strtoupper($diskType);
$hardwareItems[] = "Disk: {$diskText}";
}

if (count($hardwareItems) > 0) {
$this->io->displayDeets(['Hardware' => $hardwareItems]);
$this->io->writeln('');
}
}

$services = [];

// Add listening ports if any
Expand Down
67 changes: 60 additions & 7 deletions playbooks/server-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# 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)
Expand All @@ -11,6 +11,7 @@
# - 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
Expand Down Expand Up @@ -143,22 +144,64 @@ ensure_tools() {
local family=$1 perms=$2
export DEPLOYER_PERMS=$perms

# If the command is already installed, return
command -v ss > /dev/null 2>&1 && return 0
command -v netstat > /dev/null 2>&1 && return 0
# Check if required tools exist
command -v ss > /dev/null 2>&1 && command -v lsblk > /dev/null 2>&1 && return 0

case $family in
debian)
run_cmd apt-get update -q 2> /dev/null
run_cmd apt-get install -y -q iproute2 2> /dev/null
run_cmd apt-get install -y -q iproute2 util-linux 2> /dev/null
;;
fedora | redhat | amazon)
run_cmd yum install -y -q iproute 2> /dev/null \
|| run_cmd dnf install -y -q iproute 2> /dev/null
run_cmd yum install -y -q iproute util-linux 2> /dev/null \
|| run_cmd dnf install -y -q iproute util-linux 2> /dev/null
;;
esac
}

#
# Hardware Detection
# ----

#
# Detect CPU core count

detect_cpu_cores() {
nproc 2> /dev/null || echo "1"
}

#
# Detect total system RAM in MB

detect_ram_mb() {
free -m 2> /dev/null | awk 'NR==2 {print $2}' || echo "512"
}

#
# Detect disk type (ssd or hdd)

detect_disk_type() {
local disk_gran rotation

# Primary detection: Check discard granularity (TRIM support = SSD)
# Works reliably in virtualized environments (cloud VMs)
disk_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 $disk_gran && $disk_gran != "0B" ]]; then
echo "ssd"
return
fi

# Fallback: Check rotation flag (works for physical disks)
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
echo "hdd"
fi
}

# ----
# Service Metrics
# ----
Expand Down Expand Up @@ -332,6 +375,7 @@ get_php_fpm_metrics() {

main() {
local distro family permissions
local cpu_cores ram_mb disk_type

#
# Gather basic info
Expand All @@ -346,6 +390,11 @@ main() {
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 "✓ Checking Caddy status..."
local caddy_metrics caddy_available="false"
local caddy_version caddy_sites caddy_domains caddy_uptime caddy_active_req caddy_total_req caddy_memory
Expand Down Expand Up @@ -374,6 +423,10 @@ main() {
distro: $distro
family: $family
permissions: $permissions
hardware:
cpu_cores: $cpu_cores
ram_mb: $ram_mb
disk_type: $disk_type
caddy:
available: $caddy_available
version: ${caddy_version:-unknown}
Expand Down