Author Topic: Load alert script  (Read 10750 times)

Offline KTCHost

  • Administrator
  • Newbie
  • *****
  • Posts: 10
  • Karma: +0/-0
    • View Profile
    • KTCHost Web hosting provider - Buy web hosting, VPS, Dedicated servers
Load alert script
« on: May 11, 2017, 01:21:57 PM »
Get the process status report through e-mail for server load, you can try to add additional info to the code, to get more info through e-mail.

Simply create new file add following code in a /root/loadalert file and configure as per your requirement.

vi   /root/loadalert

   
Code: [Select]
#!/bin/bash
    #Created on October 15th, 2015
    EMAIL="your email 1"
    # For multiple E-mails.
    EMAIL1="your email 2"
    SUBJECT="Alert $(hostname) load average is $L05"
    TEMPFILE="/tmp/$(hostname)"
    echo "Load average Crossed allowed limit." >> $TEMPFILE
    echo "Hostname: $(hostname)" >> $TEMPFILE
    echo "Local Date & Time : $(date)" >> $TEMPFILE
    echo "| Uptime status: |" >> $TEMPFILE
    echo "-------------------------------------------" >> $TEMPFILE
    /usr/bin/uptime >> $TEMPFILE
    echo "-------------------------------------------" >> $TEMPFILE
    echo "| Top 20 CPU consuming processes: |" >> $TEMPFILE
    ps aux | head -1 >> $TEMPFILE
    ps -auxf | sort -nr -k 3 | head -20 >> $TEMPFILE
    echo "| Top 10 memory-consuming processes: |" >> $TEMPFILE
    ps aux --no-headers| sort -rn +3 | head >> $TEMPFILE
    echo "-------------------------------------------" >> $TEMPFILE
    echo "| Memory and Swap status: |" >> $TEMPFILE
    /usr/bin/free -m >> $TEMPFILE
    echo "-------------------------------------------" >> $TEMPFILE
    echo "| Active network connection: |" >> $TEMPFILE
    echo "-------------------------------------------" >> $TEMPFILE
    /bin/netstat -tnup | grep ESTA >> $TEMPFILE
    echo "-------------------------------------------" >> $TEMPFILE
    echo "| Disk Space information: |" >> $TEMPFILE
    echo "-------------------------------------------" >> $TEMPFILE
    /bin/df -h >> $TEMPFILE
    echo "-----------------THE END-------------------" >> $TEMPFILE
    L05="$(uptime|awk '{print $(NF-2)}'|cut -d. -f1)"
    if test $L05 -gt 5
    then
    mail -s "$SUBJECT  $L05" "$EMAIL" < $TEMPFILE
    # For multiple E-mails.
    #mail -s "$SUBJECT  $L05" "$EMAIL1" < $TEMPFILE
    fi
    rm -f $TEMPFILE

By default we recommend every minute cron to avoid any load alerts.

* * * * * /root/loadalert >/dev/null 2>&1

Let us know, if you required any further information.
█ ktchost.com - Reliable Web Hosting Provider
█ E-commerce Ready Hosting | Pure SSD Cloud/VPS | Offshore Dedicated Server
█ 24/7 Reliable Tech Support | Monitoring Service | R1Soft Backup