AMP AMP

How to stop the backup script and send an alert if the server loads higher on Oracle Linux 9.3

To Stop The Backup Script And Send An Alert If The Server Load Is Higher On Oracle Linux 9.3

Introduction

This straightforward procedure allows you to automatically halt backup operations when the server's resources are strained, and it simultaneously sends alerts to administrators. This proactive approach helps maintain system stability and data integrity by preventing resource overuse during peak times. By setting up this automated system, you can balance data protection and system performance on your Oracle Linux server.

Procedure Steps

Step 1: Check the OS version by using the below command

[root@linuxhelp ~]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="9.3"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="9.3"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Oracle Linux Server 9.3"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:9:3:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9"
ORACLE_BUGZILLA_PRODUCT_VERSION=9.3
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=9.3

Step 2: Create and Edit Script file by using the below command

[root@linuxhelp ~]# vim backup_script
#!/bin/bash
# Define the maximum limit of system load
maximum_limit=10 # Change the limit to your requirement
# Get the System load average
load_average=$(uptime | grep -o average.* | awk '{print $2}' | tr -d ',')
# Calculate the system core and system load average then convert to percentage
percentage=$(bc -l <<< "scale=2; $load_average / $(nproc) * 100" | sed 's/.000//g')
# if statement for creating conditions to make decisions
if (( $(echo "$percentage > $maximum_limit" | bc -l) ));
then
echo "Alert! The system load is above 10%, percentage load:$percentage%, load average:$load_average so Backup Stopped."
else
 echo "Success! The system load is below 10%, percentage load:$percentage%, load average:$load_average  so the Backup Started Successfully"
fi

Step 3: Give the executable permission to the file by using the below command

[root@linuxhelp ~]# chmod +x backup_script

Step 4: Long list to check the file permission by using the below command

[root@linuxhelp ~]# ll
total 8
-rw-------. 1 root root 1067 Jan  7 03:03 anaconda-ks.cfg
-rwxr-xr-x. 1 root root  764 Mar 11 04:23 backup_script
drwxr-xr-x. 2 root root    6 Jan  7 03:26 Desktop
drwxr-xr-x. 2 root root    6 Jan  7 03:26 Documents
drwxr-xr-x. 2 root root    6 Jan  7 03:26 Downloads
drwxr-xr-x. 2 root root    6 Jan  7 03:26 Music
drwxr-xr-x. 2 root root    6 Jan  7 03:26 Pictures
drwxr-xr-x. 2 root root    6 Jan  7 03:26 Public
drwxr-xr-x. 2 root root    6 Jan  7 03:26 Templates
drwxr-xr-x. 2 root root    6 Jan  7 03:26 Videos

Step 5: Check the server load by using the below command

[root@linuxhelp ~]# uptime
 04:24:14 up  4:06,  3 users,  load average: 0.00, 0.00, 0.00

Step 6: Run the backup_script file by using the below command

[root@linuxhelp ~]# ./backup_script
Success! The system load is below 10%, percentage load:0%, load average:0.00  so the Backup Started Successfully

Step 7: Open new terminal tab as shown in below image.

Step 8: Create and edit the script file to increase server load by using following command.

[root@linuxhelp ~]# vim infinite_loop
#!/bin/bash
while : true
do
echo "Running infinite loop, to exit press ctrl+c"
done

Step 9: Change the executable permission to inifinite loop script file by using the below command

[root@linuxhelp ~]# chmod +x infinite_loop

Step 10: Run the infinite_loop script file to increase server load by using the below command

[root@linuxhelp ~]# ./infinite_loop
Running infinite loop, to exit press ctrl+c
Running infinite loop, to exit press ctrl+c
Running infinite loop, to exit press ctrl+c
Running infinite loop, to exit press ctrl+c
Running infinite loop, to exit press ctrl+c
Running infinite loop, to exit press ctrl+c
Running infinite loop, to exit press ctrl+c

Step 11: Again check the server load by using the below command

[root@linuxhelp ~]# uptime
 04:29:17 up  4:11,  4 users,  load average: 0.30, 0.08, 0.02

Step 12: Again, Run the backup_script file by using the below command

[root@linuxhelp ~]# ./backup_script
Alert! The system load is above 10%, percentage load:26.00%, load average:1.06 so Backup Stopped.

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to Stop Backup Script and Send Alert if Server Load above 80% on Oracle Linux 9.3. Your feedback is much welcome.

FAQ
Q
How can I modify the load threshold (80%) to suit my server's needs?
A
You can modify the load threshold by changing the value of `load_maximum_limit` in the script to your desired percentage. It's important to choose a threshold that aligns with your server's capacity and performance requirements.
Q
What kind of alerts can be sent to administrators?
A
Alerts can be sent via email, SMS, or other notification methods. They typically include information about the high server load, timestamps, and possibly suggestions for further actions.
Q
How do I set up monitoring for server load on Oracle Linux?
A
You can set up monitoring using tools like `uptime`, `sar`, or specialized monitoring software such as Nagios. These tools can periodically check the system load average.
Q
What does "Server Load above 80%" mean?
A
"Server Load above 80%" typically refers to the system load average, a measure of the server's workload. When this load average exceeds 80%, it suggests the server is under significant load, which can affect performance.
"Server Load above 80%" typically refers to the system load average, a measure of the server's workload. When this load average exceeds 80%, it suggests the server is under significant load, which can affect performance.
Q
Why is it important to stop the backup script during high server loads?
A
When the server load is high, it indicates that system resources are under strain. Stopping the backup script temporarily helps prevent further resource consumption, ensuring the server remains responsive and stable.