Chức năng mã nguồn là sẽ thông báo email cho bạn về thông tin VPS/Server đang bị quá tải.
PHP:
#!/bin/bashEMAIL="admin@server.com" // Email cua banSUBJECT="Alert $(hostname) load average is $L05"TEMPFILE="/tmp/$(hostname)"TOPLOAD="10" // Neu VPS/Server load avarage qua 10 se thong bao cho banecho "Load average Crossed allowed limit." >> $TEMPFILEecho "Hostname: $(hostname)" >> $TEMPFILEecho "Local Date & Time : $(date)" >> $TEMPFILEecho "| Uptime status: |" >> $TEMPFILEecho "-------------------------------------------" >> $TEMPFILE/usr/bin/uptime >> $TEMPFILEecho "-------------------------------------------" >> $TEMPFILEecho "| Top 20 CPU consuming processes: |" >> $TEMPFILE
ps aux | head -1 >> $TEMPFILE
ps aux --no-headers | sort -rn +2 | head -20 >> $TEMPFILEecho "| Top 10 memory-consuming processes: |" >> $TEMPFILE
ps aux --no-headers| sort -rn +3 | head >> $TEMPFILEecho "-------------------------------------------" >> $TEMPFILEecho "| Memory and Swap status: |" >> $TEMPFILE/usr/bin/free -m >> $TEMPFILEecho "-------------------------------------------" >> $TEMPFILEecho "| Active network connection: |" >> $TEMPFILEecho "-------------------------------------------" >> $TEMPFILE/bin/netstat -tnup | grep ESTA >> $TEMPFILEecho "-------------------------------------------" >> $TEMPFILEecho "| Disk Space information: |" >> $TEMPFILEecho "-------------------------------------------" >> $TEMPFILE/bin/df -h >> $TEMPFILEecho "-----------------THE END-------------------" >> $TEMPFILE
L05="$(uptime|awk '{print $(NF-2)}'|cut -d. -f1)"if test $L05 -gt $TOPLOAD
then
mail -s "$SUBJECT $L05" "$EMAIL" < $TEMPFILE
fi
rm -f $TEMPFILE
0 comments:
Post a Comment