-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor_load_avg.sh
34 lines (27 loc) · 1.26 KB
/
monitor_load_avg.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Define Variables
export CUR_TIME="$(date +"%A %b %e %r")"
export HOSTNAME="$(hostname)"
# Retrieve the load average of the past 1 minute
export Load_AVG="$(uptime | cut -d'l' -f2 | awk '{print $3}' | cut -d. -f1)"
export LOAD_CUR="$(uptime | cut -d'l' -f2 | awk '{print $3 " " $4 " " $5}' | sed 's/,//')"
# Define Threshold. This value will be compared with the current
# load average. Set the value as per your wish.
export LIMIT=50
# Compare the current load average with the Threshold value and
# email the server administrator if the current load average
# is greater.
if [ "$Load_AVG" -gt "$LIMIT" ]; then
#Save the current running processes in a file
/bin/ps auxf >> /root/ps_output
# Save the other values in a file
echo "Current Time :: $CUR_TIME" >> /tmp/monitload.txt
echo "Current Load Average :: $LOAD_CUR" >> /tmp/monitload.txt
echo "The list of current processes is attached with the email for your reference." >> /tmp/monitload.txt
echo "Please Check... ASAP." >> /tmp/monitload.txt
# Send an email to the administrator of the server
# sendmail [email protected] "ALERT. Load average on '$HOSTNAME'" -to [email protected] < /tmp/monitload.txt
fi
# Remove the temporary log files
/bin/rm -f /tmp/monitload.txt
/bin/rm -f /root/ps_output