linux 負載報警腳本,系統負載超過一定數值,就重啓php-cgi,併發送報警短信。
- #!/bin/sh
- #description:system load average
- #author:coralzd powered by www.freebsdsystem.org
- host=$(hostname)
- channel=$(hostname | sed 's/[0-9]//g')
- runday=$(date "+%Y-%m-%d")
- IPhost=$(/sbin/ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}')
- i=10
- while [ 1 ];do
- rundaytime=$(date "+%Y-%m-%d %H:%M:%S")
- L=$(cat /proc/loadavg|cut -c1-4)
- RESULT=$(echo "$L > $i"|bc)
- if [ "${RESULT}" == "$i" ]; then
- echo "$runday" >> /var/tmp/${host}.txt
- wget http: -O /dev/null >/dev/null 2>&1 //10.10.10.10/phpsms/smsu.php?phone=15012345678\&msg=warning%20${IPhost}%20Load%20avarage%20is%20high
- /usr/local/php52/sbin/php-fpm restart
- echo "${runday}" >> /var/log/${host}.txt
- echo "The system load average is 10+ ,php-fpm already restart" >> /var/log/${host}.txt
- fi
- sleep 600
- done