Fix AWK-UNINIT issues by initializing variables in BEGIN blocks
lib/php-analyzer.sh: - Line 364: Initialize sum=0 in awk for request counting - Line 1374: Initialize sum=0 in awk for MySQL memory calculation modules/diagnostics/loadwatch-analyzer.sh: - Lines 748-752: Initialize i=0 for memory velocity parsing - Lines 794-797: Initialize i=0 for load trend parsing modules/performance/hardware-health-check.sh: - Lines 1243, 1244, 1247: Initialize sum=0 for network error metrics Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
+2
-2
@@ -361,7 +361,7 @@ calculate_avg_requests_per_minute() {
|
|||||||
|
|
||||||
# Count total requests in last N hours
|
# Count total requests in last N hours
|
||||||
local total_requests
|
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
|
if [ -z "$total_requests" ] || [ "$total_requests" -eq 0 ]; then
|
||||||
echo "0|No recent requests"
|
echo "0|No recent requests"
|
||||||
@@ -1371,7 +1371,7 @@ detect_mysql_memory_usage() {
|
|||||||
|
|
||||||
# Try to get actual memory usage from ps
|
# Try to get actual memory usage from ps
|
||||||
local mysql_rss_kb
|
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
|
if [ -n "$mysql_rss_kb" ] && [ "$mysql_rss_kb" -gt 0 ]; then
|
||||||
local mysql_rss_mb=$((mysql_rss_kb / 1024))
|
local mysql_rss_mb=$((mysql_rss_kb / 1024))
|
||||||
|
|||||||
@@ -745,11 +745,11 @@ print_status "Phase 4/4: Generating report..."
|
|||||||
# Memory growth velocity
|
# Memory growth velocity
|
||||||
if [ -f "$TEMP_DIR/memory_velocity.txt" ]; then
|
if [ -f "$TEMP_DIR/memory_velocity.txt" ]; then
|
||||||
read -r _ first_line < "$TEMP_DIR/memory_velocity.txt"
|
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)
|
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 '{for(i=1;i<=NF;i++) if($i ~ /^last=/) 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 '{for(i=1;i<=NF;i++) if($i ~ /^delta=/) 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 '{for(i=1;i<=NF;i++) if($i ~ /^rate_per_hour=/) 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 '{for(i=1;i<=NF;i++) if($i ~ /^hours_to_oom=/) 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 "Memory Growth Velocity:"
|
||||||
echo " First Available: ${FIRST_AVAIL} MiB"
|
echo " First Available: ${FIRST_AVAIL} MiB"
|
||||||
@@ -791,10 +791,10 @@ print_status "Phase 4/4: Generating report..."
|
|||||||
# Load trend direction
|
# Load trend direction
|
||||||
if [ -f "$TEMP_DIR/load_trend.txt" ]; then
|
if [ -f "$TEMP_DIR/load_trend.txt" ]; then
|
||||||
read -r _ trend_line < "$TEMP_DIR/load_trend.txt"
|
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)
|
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 '{for(i=1;i<=NF;i++) if($i ~ /^rising=/) 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 '{for(i=1;i<=NF;i++) if($i ~ /^falling=/) 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 '{for(i=1;i<=NF;i++) if($i ~ /^stable=/) 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:"
|
echo "Load Trend Direction:"
|
||||||
case "$TREND_DIR" in
|
case "$TREND_DIR" in
|
||||||
|
|||||||
@@ -1240,11 +1240,11 @@ check_network_errors() {
|
|||||||
|
|
||||||
if [ -n "$stats" ]; then
|
if [ -n "$stats" ]; then
|
||||||
# Extract key error metrics (different NICs use different naming)
|
# 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 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 '{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 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 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
|
# Accumulate totals
|
||||||
total_rx_dropped=$((total_rx_dropped + rx_dropped))
|
total_rx_dropped=$((total_rx_dropped + rx_dropped))
|
||||||
|
|||||||
Reference in New Issue
Block a user