Bash script to check server load and notify by email
Hey guys, this is the first ever post on Serverlogs. The shell scripts are always to handy to do some tasks on a Linux based server for SysAdmins, they can automate everything they do frequently through a shell script. Here I’m going to introduce my first ever script to monitor server load on a Linux based system and alert us via email if it exceeded a triggering value. This will definitely helps us to investigate the server load issues as soon as possible without any paid monitoring addons, I will enhance this more soon to include few other information which will help us to troubleshoot the load issue on a server.
Let’s see the script here:
#!/bin/bash
#
# Date: Jan 18th 2017
# Author: Muhammed Fasal (https://fasal.cf)
# Bash script for monitoring server load and alert us via Email if it exceeds a certain value
#
# Copyright (C) 2017 Muhammed Fasal
#
#variable for triggering
trig=5.00
#Get current load on the server
load=`cat /proc/loadavg | awk '{print $1}'`
#Check both
if [[ $load > $trig ]];
then
echo -e "\n\nYour server load is High. Check Immediatly\n\nServer load : $load " | mail -s "High Server Load [$load]" user@example.com
fi
You can adjust triggering value there on ‘trig‘ variable, default would be 5 also replace ‘user@example.com‘ with your email address where you wish to receive the alert. Save this on to a file check_load.sh, or you can download this directly from here. Once you have saved/downloaded the file there, create below cron job on the server to monitor the server.
*/2 * * * * /bin/bash /path/to/the/folder/check_load.sh
The above crob job will monitor the server on every 2 minutes, and alert us if there any issue with the server load.
If you run into any issues, please contact me at [fasal(at)serverlogs(dot)tk] and let me know thoughts or ideas for improvement. Thanks!
Nice tool
Hello, all the time i used to check weblog posts here
early in the break of day, as i love to gain knowledge of
more and more.
Here is my site :: Buy CBD
Excellent article. Keep writing such kind
of info on your page. Im really impressed by it.
Hello there, You have performed a fantastic job.
I’ll definitely digg it and in my opinion recommend to my friends.
I’m confident they will be benefited from this website.