diff --git a/modules/website/website-slowness-diagnostics.sh b/modules/website/website-slowness-diagnostics.sh index 40dac92..a95d8c2 100755 --- a/modules/website/website-slowness-diagnostics.sh +++ b/modules/website/website-slowness-diagnostics.sh @@ -1955,6 +1955,144 @@ analyze_redirects() { return 0 } +################################################################################ +# PERFORMANCE SCORING +################################################################################ + +# Calculate overall performance score based on issues found +calculate_performance_score() { + local temp_dir="$1" + + # Count CRITICAL and WARNING issues + local critical_count=0 + local warning_count=0 + + for file in "$temp_dir"/*.tmp; do + [ -f "$file" ] || continue + critical_count=$((critical_count + $(grep -c "CRITICAL" "$file" 2>/dev/null || echo 0))) + warning_count=$((warning_count + $(grep -c "WARNING" "$file" 2>/dev/null || echo 0))) + done + + # Calculate score (100 - issues) + local score=$((100 - (critical_count * 10) - (warning_count * 2))) + [ $score -lt 0 ] && score=0 + [ $score -gt 100 ] && score=100 + + # Determine grade + local grade + if [ $score -ge 90 ]; then + grade="A - EXCELLENT" + elif [ $score -ge 80 ]; then + grade="B - GOOD" + elif [ $score -ge 70 ]; then + grade="C - FAIR" + elif [ $score -ge 60 ]; then + grade="D - POOR" + else + grade="F - CRITICAL" + fi + + echo "$score|$grade|$critical_count|$warning_count" +} + +# Save report to file +save_report_to_file() { + local domain="$1" + local temp_dir="$2" + local report_file="/tmp/slowness-report-${domain}-$(date +%Y%m%d-%H%M%S).txt" + + { + echo "================================================================================" + echo " WEBSITE SLOWNESS DIAGNOSTIC REPORT" + echo " Domain: $domain" + echo " Generated: $(date)" + echo "================================================================================" + echo "" + + # Add performance score at top + read_analysis_data "framework_info.tmp" + echo "" + + # Rest of report + echo "================================================================================" + echo " Framework Information" + echo "================================================================================" + read_analysis_data "framework_info.tmp" + echo "" + + echo "================================================================================" + echo " System Information" + echo "================================================================================" + read_analysis_data "system_info.tmp" + echo "" + + echo "================================================================================" + echo " Database Analysis" + echo "================================================================================" + read_analysis_data "database_analysis.tmp" + echo "" + + echo "================================================================================" + echo " Configuration Analysis" + echo "================================================================================" + read_analysis_data "config_analysis.tmp" + echo "" + + echo "================================================================================" + echo " Resource Usage & Limits" + echo "================================================================================" + read_analysis_data "resource_analysis.tmp" + echo "" + + echo "================================================================================" + echo " WordPress-Specific Analysis" + echo "================================================================================" + read_analysis_data "wordpress_analysis.tmp" + echo "" + + echo "================================================================================" + echo " Log Analysis" + echo "================================================================================" + read_analysis_data "log_analysis.tmp" + echo "" + + echo "================================================================================" + echo " Caching Status" + echo "================================================================================" + read_analysis_data "caching_info.tmp" + echo "" + + echo "================================================================================" + echo " TTFB Measurements" + echo "================================================================================" + read_analysis_data "ttfb_data.tmp" + echo "" + + echo "================================================================================" + echo " Image Analysis" + echo "================================================================================" + read_analysis_data "image_analysis.tmp" + echo "" + + echo "================================================================================" + echo " Redirect Chain Analysis" + echo "================================================================================" + read_analysis_data "redirect_analysis.tmp" + echo "" + + echo "================================================================================" + echo " END OF REPORT" + echo "================================================================================" + } > "$report_file" 2>/dev/null + + if [ -f "$report_file" ]; then + echo "$report_file" + return 0 + else + return 1 + fi +} + ################################################################################ # REPORT GENERATION ################################################################################ @@ -1962,6 +2100,22 @@ analyze_redirects() { generate_report() { print_section "=== SLOWNESS DIAGNOSTIC REPORT ===" + # Calculate and display performance score + local score_data=$(calculate_performance_score "$TEMP_DIR") + local score=$(echo "$score_data" | cut -d'|' -f1) + local grade=$(echo "$score_data" | cut -d'|' -f2) + local critical=$(echo "$score_data" | cut -d'|' -f3) + local warning=$(echo "$score_data" | cut -d'|' -f4) + + echo "" + echo "╔════════════════════════════════════════════════════════════════╗" + echo "║ PERFORMANCE SCORE SUMMARY ║" + echo "╠════════════════════════════════════════════════════════════════╣" + printf "║ Overall Grade: %-51s║\n" "$grade" + printf "║ Score: %d/100 | Issues: %d Critical, %d Warning(s)%15s║\n" "$score" "$critical" "$warning" "" + echo "╚════════════════════════════════════════════════════════════════╝" + echo "" + # Read and display all analysis data print_banner "Framework Information" read_analysis_data "framework_info.tmp" | while read -r line; do @@ -2205,6 +2359,20 @@ run_diagnostics() { print_banner "Generating report..." generate_report + # Offer to save report to file + echo "" + read -p "Save report to file? (y/n): " save_choice + if [[ "$save_choice" =~ ^[Yy]$ ]]; then + local report_file=$(save_report_to_file "$domain" "$TEMP_DIR") + if [ $? -eq 0 ]; then + echo "" + print_success "Report saved to: $report_file" + echo "" + else + print_error "Failed to save report" + fi + fi + press_enter return 0 }