- Free disk space
- CPU load
You can create the two scripts below and edit the MAILTO and TRIGGER variables to suit your needs /usr/local/bin/monitor-load.sh:
#!/bin/bash TRIGGER=2.00 MAILTO=mail@somedomain.com host=`hostname -f` load=`cat /proc/loadavg | awk '{print $2}'` response=`echo | awk -v T=$TRIGGER -v L=$load 'BEGIN{if ( L > T){ print "greater"}}'` if [[ $response = "greater" ]] then #capture top command output for the mail body body=`top -n 1 -b` echo "$body\n."|mail -s "High load on $host - [ $load ]" $MAILTO fi/usr/local/bin/monitor-disk-usage.sh:
#!/bin/bash MAILTO=mail@somedomain.com TRIGGER=80 HOST=`hostname -f` CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g') if [ "$CURRENT" -gt "$TRIGGER" ] ; then mail -s "Disk Space Alert for $HOST" $MAILTO << EOF The root partition of '$HOST' remaining free space is critically low. Used: $CURRENT% EOF fi
Make these two scripts executable:
chmod +x /usr/local/bin/monitor-load.sh chmod +x /usr/local/bin/monitor-disk-usage.shNow schedule these script in system cron jobs:
/etc/cron.d/monitor:
# Check server load and diskspace * * * * * root /usr/local/bin/monitor-load.sh 0 7,16 * * * root /usr/local/bin/monitor-disk-usage.shThis will check the server load every minute and disk space at 7am and 4pm. Finally it's wise to test if mails sent from console arrive. Change the e-mail address in this command and run it:
echo "."|mail -s "Test mail from console" mail@somedomain.com
Hai Merijn,
ReplyDeleteThe last cronjob will run every minute from 7:00 to 7:59 and from 16:00 to 16:59.
Thanks! I've adjusted it.
DeleteHi Merijn,
ReplyDeletenice scripts. We use dedicated hardware an monit for this purposes. I'll post a howto in the forum.
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteEnjoyed reading the article above really explains everything in detail,the article is very interesting and effective.Thank you and good luck for the upcoming articles. if you written on Linux Classes please share.
ReplyDeleteMade me feel rapture with your work, https://onmoviesapk.com/firestick/
ReplyDeleteEnjoyed reading the article above really explains everything in detail,the article is very interesting and effective
ReplyDeletePython classes in Nashik
And isn't it just so pretty to think financial planner oxnard
ReplyDeletehttps://saglamproxy.com
ReplyDeletemetin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
NU228