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:
+38
-27
@@ -742,50 +742,61 @@ calculate_server_memory_capacity() {
|
|||||||
local pool_count=0
|
local pool_count=0
|
||||||
local details=""
|
local details=""
|
||||||
|
|
||||||
# Iterate through all users
|
# Iterate through all users and their domains
|
||||||
while IFS= read -r username; do
|
while IFS= read -r username; do
|
||||||
[ -z "$username" ] && continue
|
[ -z "$username" ] && continue
|
||||||
|
|
||||||
# Find FPM pool config
|
# Get all domains for this user
|
||||||
local pool_config
|
local user_domains
|
||||||
pool_config=$(find_fpm_pool_config "$username")
|
user_domains=$(get_user_domains "$username")
|
||||||
|
|
||||||
if [ -z "$pool_config" ] || [ ! -f "$pool_config" ]; then
|
while IFS= read -r domain; do
|
||||||
continue
|
[ -z "$domain" ] && continue
|
||||||
fi
|
|
||||||
|
|
||||||
pool_count=$((pool_count + 1))
|
# Find FPM pool config for this domain
|
||||||
|
local pool_config
|
||||||
|
pool_config=$(find_fpm_pool_config "$username" "$domain")
|
||||||
|
|
||||||
# Get max_children from pool config
|
if [ -z "$pool_config" ] || [ ! -f "$pool_config" ]; then
|
||||||
local max_children
|
continue
|
||||||
max_children=$(grep "^pm.max_children" "$pool_config" | awk -F'=' '{print $2}' | tr -d ' ')
|
fi
|
||||||
|
|
||||||
if [ -z "$max_children" ] || [ "$max_children" -eq 0 ]; then
|
pool_count=$((pool_count + 1))
|
||||||
max_children=5 # Safe default if not set
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get average memory per process
|
# Get max_children from pool config
|
||||||
local memory_stats
|
local max_children
|
||||||
memory_stats=$(calculate_memory_per_process "$username")
|
max_children=$(grep "^pm.max_children" "$pool_config" | awk -F'=' '{print $2}' | tr -d ' ')
|
||||||
|
|
||||||
local avg_kb
|
if [ -z "$max_children" ] || [ "$max_children" -eq 0 ]; then
|
||||||
avg_kb=$(echo "$memory_stats" | cut -d'|' -f1)
|
max_children=5 # Safe default if not set
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$avg_kb" -eq 0 ]; then
|
# Get average memory per process from pool name
|
||||||
|
local pool_name
|
||||||
|
pool_name=$(grep "^\[" "$pool_config" | tr -d '[]' | head -1)
|
||||||
|
|
||||||
|
# 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 [ -z "$avg_kb" ] || [ "$avg_kb" -eq 0 ]; then
|
||||||
# No active processes, estimate 50MB per process (conservative)
|
# No active processes, estimate 50MB per process (conservative)
|
||||||
avg_kb=$((50 * 1024))
|
avg_kb=$((50 * 1024))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local avg_mb=$((avg_kb / 1024))
|
local avg_mb=$((avg_kb / 1024))
|
||||||
|
|
||||||
# Calculate max memory for this pool
|
# Calculate max memory for this pool
|
||||||
local pool_max_mb=$((max_children * avg_mb))
|
local pool_max_mb=$((max_children * avg_mb))
|
||||||
total_required_mb=$((total_required_mb + pool_max_mb))
|
total_required_mb=$((total_required_mb + pool_max_mb))
|
||||||
total_max_children=$((total_max_children + max_children))
|
total_max_children=$((total_max_children + max_children))
|
||||||
|
|
||||||
# Add to details
|
# 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"
|
done <<< "$users"
|
||||||
|
|
||||||
# Calculate percentage
|
# Calculate percentage
|
||||||
|
|||||||
Reference in New Issue
Block a user