Write the missing code at the end of this script to provide a nicely structured output.


```bash
#!/bin/bash

print_header() {
    echo "-----------------------------------------------------"
    echo "$(date)"
    echo "Diagnostic checks on $(hostname)"
    echo "-----------------------------------------------------"
}

get_load_averages() {
    echo "System Load Averages:"
    cat /proc/loadavg | awk '{print "1 min:", $1, "5 mins:", $2, "15 mins:", $3}'
}

get_cpu_info() {
    cpu_info=$(top -bn1 | grep 'Cpu(s)')
    read -r us sy ni id wa hi si st <<<$(echo $cpu_info | awk '{print $2,$4,$6,$8,$10,$12,$14,$16}' | tr -d '%usyinidwahisti,')
    echo "CPU Information:"
    echo "User Space (%us): $us "
    echo "System (%sy): $sy "
    echo "Nice (%ni): $ni "
    echo "Idle (%id): $id "
    echo "I/O Wait (%wa): $wa "
    echo "Hardware IRQ (%hi): $hi "
    echo "Software Interrupts (%si): $si "
    echo "Steal time (%st): $st "
}

get_memory_usage() {
    echo "Memory Usage:"
    free -h
}

check_ve_disk_space() {
    echo "VEs with critical disk space usage:"
    sudo vzlist -Ho veid,diskspace,diskspace.s | awk '{usage=($2/($3*100))*100; if (usage > 95) print $1, "- "usage"%"}'
}

get_cgroup_activity() {
    echo "CGroup Activity Overview:"
    echo "Total cgroups activity across all slices:"
    cat /proc/cgroups | awk '{ sum+=$3} END { print sum }'
}

count_cgroup_dirs() {
    echo "Count of directory entries in key cgroup subdirectories:"
    for i in $(ls -d /sys/fs/cgroup/memory/machine.slice/*/); do
        echo "$i: $(sudo find $i -type d 2>/dev/null | wc -l)"
    done | sort -nk 2 | tail -5
}

check_uninterruptible_procs() {
    d_procs=$(ps -eo ppid,pid,user,stat,pcpu,comm,wchan:32 | awk '$4~/^D/ {print $0}')
    if [[ -n "$d_procs" ]]; then
        echo "Processes in Uninterruptible Sleep State:"
        echo "$d_procs"
    else
        echo "No processes in uninterruptible sleep state."
    fi
}

check_zombie_procs() {
    z_procs=$(ps -eo ppid,pid,user,stat,pcpu,comm,wchan:32 | awk '$4~/^Z/ && $5 > 0.0 {print $0}')
    total_zombies=$(ps -eo stat | awk '$1~/^Z/ {count++} END {print count}')

    if [[ -n "$z_procs" ]]; then
        echo "Problematic Zombie Processes Detected (CPU Usage > 0.0%):"
        echo "$z_procs"
    elif [[ "$total_zombies" -gt 0 ]]; then
        echo "Zombies Detected: $total_zombies (None using CPU)"
    else
        echo "No zombie processes found."
    fi
}

get_top_memory_procs() {
    echo "Top 5 Memory Consuming Processes:"
    ps aux --sort -rss | head -n 5
}

check_ve_d_state() {
    d_state_processes=$(sudo vzps axww -eLo veid,state | awk '$2=="D" {print $1}' | sort | uniq -c | sort -nr | awk '$1 > 2 {print $2, $1}')

    if [[ -n "$d_state_processes" ]]; then
        echo "VEs with elevated D state processes:"
        echo "$d_state_processes"

        highest_veid=$(echo "$d_state_processes" | awk '{print $1}' | head -1)
        analyze_ve "$highest_veid"
    else
        echo "There are no VEs with D state processes exceeding the count of 2."
    fi
}

analyze_ve() {
    veid=$1
    echo "Analyzing processes for VEID $veid with the highest number of D state processes:"
    sudo vzps -E $veid -eo pid,cpu,etime,rsz,cmd --sort=-cpu | head -5
    echo ""

    echo "Long running processes in VEID $veid:"
    sudo vzps -E $veid -eo pid,cmd,etime | awk '{split($3,a,"-"); if (a[1] > 0 || a[2] > 100) print $0}' | head -5
    echo ""

    echo "Analyzing network traffic for VEID $veid:"
    sudo vznetstat -v $veid -r
    echo ""
}

get_top_ve_memory_utilization() {
    echo "Top 5 VEs sorted by Memory Guarantee Utilization:"
    sudo vzlist -o veid,kmemsize,oomguarpages,numproc,numtcpsock,tcpsndbuf,tcprcvbuf --sort=-oomguarpages | head -5
}

get_top_ve_output_traffic() {
    echo "Top 5 VEs sorted by Output Traffic:"
    echo "VEID OUTPUT"
    for veid in $(sudo vzlist -Ho veid); do
        output=$(sudo vznetstat -v $veid -r | awk -v veid="$veid" '/^[0-9]/ {sum+=$5} END {print veid, sum}')
        echo "$output"
    done | sort -k2,2hr | head -5
}

check_network_utilization() {
    echo "Network Utilization:"
    for veid in $(sudo vzlist -Ho veid); do
        echo "VEID $veid:"
        sudo vznetstat -v $veid | awk '/^[0-9]/ {print $5, $6}' | column -t -s, -o ' | '
    done
}

check_disk_io() {
    echo "Disk I/O Statistics:"
    for veid in $(sudo vzlist -Ho veid); do
        echo "VEID $veid:"
        sudo vzdiskstats -v $veid | awk '/^[0-9]/ {print $4, $5, $6}' | column -t -s, -o ' | '
    done
}

check_swap_usage() {
    echo "Swap Usage:"
    for veid in $(sudo vzlist -Ho veid); do
        echo "VEID $veid:"
        sudo swapon -s | grep $veid | awk '{print $3, $4}' | column -t -s, -o ' | '
    done
}

check_process_count() {
    echo "Process Count:"
    for veid in $(sudo vzlist -Ho veid); do
        echo "VEID $veid:"
        sudo vzps -E $veid -o pid | wc -l
    done
}

check_ve_resource_limits() {
    echo "VE Resource Limits:"
    for veid in $(sudo vzlist -Ho veid); do
        echo "VEID $veid:"
        sudo vzlist -H -o veid,kmemsize,diskspace,cpu,numproc --select cpuused=100,diskspaceused=90,kmemsizeused=80,numprocused=70 | grep $veid
    done
}

check_service_availability() {
    echo "Service Availability:"
    for veid in $(sudo vzlist -Ho veid); do
        echo "VEID $veid:"
        sudo vzctl exec $veid systemctl list-units --type service --state failed
    done
}

analyze_log_files() {
    echo "Log File Analysis:"
    for veid in $(sudo vzlist -Ho veid); do
        echo "VEID $veid:"
        sudo vzctl exec $veid grep -i -r 'error|warning' /var/log/*
    done
}

provide_plan_of_action() {
    echo "Plan of Action:"
    echo ""

 
    high_cpu_ves=$(sudo vzlist -o veid,cpu --sort=-cpu | head -5)
    if [[ -n "$high_cpu_ves" ]]; then
        echo "The following VEs have high CPU usage:"
        echo "$high_cpu_ves"
        echo "Consider investigating and optimizing resource-intensive processes or adjusting CPU allocation."
        echo ""
    fi

    high_mem_ves=$(sudo vzlist -o veid,memory --sort=-memory | head -5)
    if [[ -n "$high_mem_ves" ]]; then
        echo "The following VEs have high memory usage:"
        echo "$high_mem_ves"
        echo "Consider increasing memory allocation or optimizing memory-intensive processes."
        echo ""
    fi

    problematic_ve=$(sudo vzlist -Ho veid | head -1)
    echo "It is advised to reboot VE $problematic_ve due to high resource consumption."
    echo "This will help reset the VE's resource usage and potentially resolve any related issues."
    echo ""
}

main() {
    print_header
    get_load_averages
    get_cpu_info
    get_memory_usage
    check_ve_disk_space
    get_cgroup_activity
    count_cgroup_dirs
    check_uninterruptible_procs
    check_zombie_procs
    get_top_memory_procs
    check_ve_d_state
    get_top_ve_memory_utilization
    get_top_ve_output_traffic
    check_network_utilization
    check_disk_io
    check_swap_usage
    check_process_count
    check_ve_resource_limits
    check_service_availability
    analyze_log_files
    provide_plan_of_action
}