diff --git a/lib/php-analyzer.sh b/lib/php-analyzer.sh index 9988ff4..3d0cf13 100644 --- a/lib/php-analyzer.sh +++ b/lib/php-analyzer.sh @@ -361,7 +361,7 @@ calculate_avg_requests_per_minute() { # Count total requests in last N hours local total_requests - total_requests=$(find "$access_logs" -mmin -$((hours * 60)) -exec wc -l {} \; 2>/dev/null | awk '{sum+=$1} END {print sum}') + total_requests=$(find "$access_logs" -mmin -$((hours * 60)) -exec wc -l {} \; 2>/dev/null | awk 'BEGIN {sum=0} {sum+=$1} END {print sum}') if [ -z "$total_requests" ] || [ "$total_requests" -eq 0 ]; then echo "0|No recent requests" @@ -1371,7 +1371,7 @@ detect_mysql_memory_usage() { # Try to get actual memory usage from ps local mysql_rss_kb - mysql_rss_kb=$(ps aux | grep -E "[m]ysqld|[m]ariadbd" | awk '{sum+=$6} END {print sum}') + mysql_rss_kb=$(ps aux | grep -E "[m]ysqld|[m]ariadbd" | awk 'BEGIN {sum=0} {sum+=$6} END {print sum}') if [ -n "$mysql_rss_kb" ] && [ "$mysql_rss_kb" -gt 0 ]; then local mysql_rss_mb=$((mysql_rss_kb / 1024)) diff --git a/modules/diagnostics/loadwatch-analyzer.sh b/modules/diagnostics/loadwatch-analyzer.sh index eb589e7..6722754 100755 --- a/modules/diagnostics/loadwatch-analyzer.sh +++ b/modules/diagnostics/loadwatch-analyzer.sh @@ -745,11 +745,11 @@ print_status "Phase 4/4: Generating report..." # Memory growth velocity if [ -f "$TEMP_DIR/memory_velocity.txt" ]; then read -r _ first_line < "$TEMP_DIR/memory_velocity.txt" - FIRST_AVAIL=$(echo "$first_line" | awk '{for(i=1;i<=NF;i++) if($i ~ /^first=/) print $i}' | cut -d= -f2) - LAST_AVAIL=$(echo "$first_line" | awk '{for(i=1;i<=NF;i++) if($i ~ /^last=/) print $i}' | cut -d= -f2) - DELTA=$(echo "$first_line" | awk '{for(i=1;i<=NF;i++) if($i ~ /^delta=/) print $i}' | cut -d= -f2) - RATE=$(echo "$first_line" | awk '{for(i=1;i<=NF;i++) if($i ~ /^rate_per_hour=/) print $i}' | cut -d= -f2) - HOURS_TO_OOM=$(echo "$first_line" | awk '{for(i=1;i<=NF;i++) if($i ~ /^hours_to_oom=/) print $i}' | cut -d= -f2) + FIRST_AVAIL=$(echo "$first_line" | awk 'BEGIN {i=0} {for(i=1;i<=NF;i++) if($i ~ /^first=/) print $i}' | cut -d= -f2) + LAST_AVAIL=$(echo "$first_line" | awk 'BEGIN {i=0} {for(i=1;i<=NF;i++) if($i ~ /^last=/) print $i}' | cut -d= -f2) + DELTA=$(echo "$first_line" | awk 'BEGIN {i=0} {for(i=1;i<=NF;i++) if($i ~ /^delta=/) print $i}' | cut -d= -f2) + RATE=$(echo "$first_line" | awk 'BEGIN {i=0} {for(i=1;i<=NF;i++) if($i ~ /^rate_per_hour=/) print $i}' | cut -d= -f2) + HOURS_TO_OOM=$(echo "$first_line" | awk 'BEGIN {i=0} {for(i=1;i<=NF;i++) if($i ~ /^hours_to_oom=/) print $i}' | cut -d= -f2) echo "Memory Growth Velocity:" echo " First Available: ${FIRST_AVAIL} MiB" @@ -791,10 +791,10 @@ print_status "Phase 4/4: Generating report..." # Load trend direction if [ -f "$TEMP_DIR/load_trend.txt" ]; then read -r _ trend_line < "$TEMP_DIR/load_trend.txt" - TREND_DIR=$(echo "$trend_line" | awk '{for(i=1;i<=NF;i++) if($i ~ /^direction=/) print $i}' | cut -d= -f2) - RISING_COUNT=$(echo "$trend_line" | awk '{for(i=1;i<=NF;i++) if($i ~ /^rising=/) print $i}' | cut -d= -f2) - FALLING_COUNT=$(echo "$trend_line" | awk '{for(i=1;i<=NF;i++) if($i ~ /^falling=/) print $i}' | cut -d= -f2) - STABLE_COUNT=$(echo "$trend_line" | awk '{for(i=1;i<=NF;i++) if($i ~ /^stable=/) print $i}' | cut -d= -f2) + TREND_DIR=$(echo "$trend_line" | awk 'BEGIN {i=0} {for(i=1;i<=NF;i++) if($i ~ /^direction=/) print $i}' | cut -d= -f2) + RISING_COUNT=$(echo "$trend_line" | awk 'BEGIN {i=0} {for(i=1;i<=NF;i++) if($i ~ /^rising=/) print $i}' | cut -d= -f2) + FALLING_COUNT=$(echo "$trend_line" | awk 'BEGIN {i=0} {for(i=1;i<=NF;i++) if($i ~ /^falling=/) print $i}' | cut -d= -f2) + STABLE_COUNT=$(echo "$trend_line" | awk 'BEGIN {i=0} {for(i=1;i<=NF;i++) if($i ~ /^stable=/) print $i}' | cut -d= -f2) echo "Load Trend Direction:" case "$TREND_DIR" in diff --git a/modules/performance/hardware-health-check.sh b/modules/performance/hardware-health-check.sh index a7cc47d..8fd5eec 100755 --- a/modules/performance/hardware-health-check.sh +++ b/modules/performance/hardware-health-check.sh @@ -1240,11 +1240,11 @@ check_network_errors() { if [ -n "$stats" ]; then # Extract key error metrics (different NICs use different naming) - local rx_dropped=$(echo "$stats" | grep -iE "rx.*drop|rx_discards" | awk '{sum+=$2} END {print sum+0}') - local tx_dropped=$(echo "$stats" | grep -iE "tx.*drop|tx_discards" | awk '{sum+=$2} END {print sum+0}') + local rx_dropped=$(echo "$stats" | grep -iE "rx.*drop|rx_discards" | awk 'BEGIN {sum=0} {sum+=$2} END {print sum+0}') + local tx_dropped=$(echo "$stats" | grep -iE "tx.*drop|tx_discards" | awk 'BEGIN {sum=0} {sum+=$2} END {print sum+0}') local rx_errors=$(echo "$stats" | grep -iE "^[[:space:]]*rx_errors" | awk '{print $2}') local tx_errors=$(echo "$stats" | grep -iE "^[[:space:]]*tx_errors" | awk '{print $2}') - local crc_errors=$(echo "$stats" | grep -iE "crc.*error|rx_crc" | awk '{sum+=$2} END {print sum+0}') + local crc_errors=$(echo "$stats" | grep -iE "crc.*error|rx_crc" | awk 'BEGIN {sum=0} {sum+=$2} END {print sum+0}') # Accumulate totals total_rx_dropped=$((total_rx_dropped + rx_dropped))