-
Notifications
You must be signed in to change notification settings - Fork 23
/
7load_check
69 lines (61 loc) · 1.66 KB
/
7load_check
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
export NVOC="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source ${NVOC}/1bash
WARNING_LOG="${NVOC}/5_watchdoglog"
LOG_FILE="${NVOC}/nvoc_logs/watchdog-screenlog.0"
while true
do
# If 1, 5 and 15 min load average are more than double cpu core give warning
HIGH_AVERAGE=$(( $(nproc) * 2 ))
AVERAGES=$(uptime | sed 's/.*: //g')
echo "Load Average: $AVERAGES" | tee -a ${LOG_FILE}
# Prevent slow single core cpus gives warning
if [[ "$HIGH_AVERAGE" < 4 ]]
then
HIGH_AVERAGE=4
fi
AVERAGE_1=$(echo "$AVERAGES" | cut -d"," -f1)
if (( $(echo "$AVERAGE_1 $HIGH_AVERAGE" | awk '{print ($1 > $2)}') ))
then
AVRG_1="HIGH"
else
AVRG_1="OK"
fi
AVERAGE_5=$(echo "$AVERAGES" | cut -d"," -f2)
if (( $(echo "$AVERAGE_5 $HIGH_AVERAGE" | awk '{print ($1 > $2)}') ))
then
AVRG_5="HIGH"
else
AVRG_5="OK"
fi
AVERAGE_15=$(echo "$AVERAGES" | cut -d"," -f3)
if (( $(echo "$AVERAGE_15 $HIGH_AVERAGE" | awk '{print ($1 > $2)}') ))
then
AVRG_15="HIGH"
else
AVRG_15="OK"
fi
if [[ $plusCPU == "NO" ]]
then
if [[ $AVRG_1 == "HIGH" ]] && [[ $AVRG_5 == "HIGH" ]] && [[ $AVRG_15 == "HIGH" ]]
then
echo "WARNING: $(date) - Load Averages are too high: $AVERAGES" | tee -a ${WARNING_LOG}
if [[ $TELEGRAM_ALERTS == "YES" ]]
then
bash "${NVOC}/telegram"
fi
if [[ $HIGH_LOAD_REBOOT == "YES" ]]
then
echo "WARNING: $(date) - Rebooting system in 5 sec" | tee -a ${WARNING_LOG}
sleep 5
if [[ SYSRQ_REBOOT == "YES" ]]
then
sudo bash ${NVOC}/sysrq_reboot.sh
else
sudo reboot -f
fi
fi
fi
fi
sleep 30
done