Fix memory capacity calculation to iterate through domains not just users

Problem:
- calculate_server_memory_capacity() showed '0MB required'
- Only iterated through users, called find_fpm_pool_config() with username only
- cPanel uses domain-based pool configs (domain.conf not username.conf)
- Result: No pools found, 0MB calculated

Fix:
- Added nested loop: users → domains
- Pass both username AND domain to find_fpm_pool_config()
- Extract pool name from config file to get actual process memory
- Use get_fpm_memory_usage(pool_name) directly instead of calculate_memory_per_process()
- Added domain to details output format

Changes:
- Lines 745-800: Rewrote user iteration to include domain loop
- Now correctly finds pools like pickledperil.com.conf
- Calculates actual memory usage per pool

Result:
- Memory capacity analysis now shows real data
- Proper OOM risk assessment
This commit is contained in:
cschantz
2025-12-03 01:23:34 -05:00
parent b2e6af9f5e
commit 083d0c5b8b
+21 -10
View File
@@ -742,13 +742,20 @@ calculate_server_memory_capacity() {
local pool_count=0
local details=""
# Iterate through all users
# Iterate through all users and their domains
while IFS= read -r username; do
[ -z "$username" ] && continue
# Find FPM pool config
# Get all domains for this user
local user_domains
user_domains=$(get_user_domains "$username")
while IFS= read -r domain; do
[ -z "$domain" ] && continue
# Find FPM pool config for this domain
local pool_config
pool_config=$(find_fpm_pool_config "$username")
pool_config=$(find_fpm_pool_config "$username" "$domain")
if [ -z "$pool_config" ] || [ ! -f "$pool_config" ]; then
continue
@@ -764,14 +771,17 @@ calculate_server_memory_capacity() {
max_children=5 # Safe default if not set
fi
# Get average memory per process
local memory_stats
memory_stats=$(calculate_memory_per_process "$username")
# Get average memory per process from pool name
local pool_name
pool_name=$(grep "^\[" "$pool_config" | tr -d '[]' | head -1)
local avg_kb
avg_kb=$(echo "$memory_stats" | cut -d'|' -f1)
# Get memory usage for this specific pool
local avg_kb=0
if [ -n "$pool_name" ]; then
avg_kb=$(get_fpm_memory_usage "$pool_name")
fi
if [ "$avg_kb" -eq 0 ]; then
if [ -z "$avg_kb" ] || [ "$avg_kb" -eq 0 ]; then
# No active processes, estimate 50MB per process (conservative)
avg_kb=$((50 * 1024))
fi
@@ -784,8 +794,9 @@ calculate_server_memory_capacity() {
total_max_children=$((total_max_children + max_children))
# Add to details
details+="$username|$max_children|${avg_mb}MB|${pool_max_mb}MB"$'\n'
details+="$domain|$username|$max_children|${avg_mb}MB|${pool_max_mb}MB"$'\n'
done <<< "$user_domains"
done <<< "$users"
# Calculate percentage