HEX
Server: LiteSpeed
System: Linux CentOS-79-64-minimal 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: vishn3436 (5293)
PHP: 8.0.15
Disabled: NONE
Upload Files
File: //scripts/checkMaxLoad.sh
#!/bin/bash

# Set the maximum load threshold
MAX_LOAD=10

# Loop through all SAR log files (sa01 to sa31)
for day in {01..31}; do
    # Construct the SAR log file path
    SAR_FILE="/var/log/sa/sa$day"

    # Check if the SAR log file exists
    if [[ -f "$SAR_FILE" ]]; then
        echo "Checking $SAR_FILE..."

        # Extract the load average data using sar -q and check if it exceeds MAX_LOAD
        sar -q -f "$SAR_FILE" | awk -v max_load="$MAX_LOAD" -v day="$day" '
        # Skip headers and process only data lines
        /^[0-9][0-9]:[0-9][0-9]:[0-9][0-9] (AM|PM)/ {
            # Combine the timestamp (columns 1 and 2)
            timestamp = $1 " " $2;

            # Extract ldavg-1 (column 6), ldavg-5 (column 7), and ldavg-15 (column 8)
            ldavg1 = $6 + 0;  # Force numeric conversion
            ldavg5 = $7 + 0;  # Force numeric conversion
            ldavg15 = $8 + 0; # Force numeric conversion

            # Check if any of the load averages exceed the threshold
            if (ldavg1 > max_load || ldavg5 > max_load || ldavg15 > max_load) {
                printf "On day %02d, load exceeded %d at: %s Load averages: %.2f %.2f %.2f\n", day, max_load, timestamp, ldavg1, ldavg5, ldavg15;
            }
        }'
    else
        echo "File $SAR_FILE does not exist."
    fi
done