Bash script for monitoring site responsiveness
Posted by: Todd
on Jul 22nd, 2009 at 5:04 pm
I just put this script in cron to check how fast a site I'm hosting is responding every 15 minutes. If the response time comes back too slow, it emails me.
Just in case anybody out there was looking for something like this.
output="path/to/tmp/file"
url="url.to.monitor.com"
download="downloaded_file_to_delete.html"
#number of seconds to respond
gap=15
rm -f $output
rm -f $download
first=`date +"%T"`
start_min=${first:3:2}
start_sec=${first:6:2}
wget -a $output -nv $url
next=`cat $output`
end_min=${next:3:2}
end_sec=${next:6:2}
alert="no"
sec_dif=$((end_sec-start_sec))
min_dif=$[end_min-start_min]
if [ "$min_dif" -ne "0" ]
then
alert="yes"
else
if [ $sec_dif -gt $gap ] ; then
alert="yes"
fi
fi
if [ $alert == "yes" ]
then
mail -s "$url is taking $sec_dif seconds to respond" "your@email.com" < $output
fi
Just in case anybody out there was looking for something like this.
output="path/to/tmp/file"
url="url.to.monitor.com"
download="downloaded_file_to_delete.html"
#number of seconds to respond
gap=15
rm -f $output
rm -f $download
first=`date +"%T"`
start_min=${first:3:2}
start_sec=${first:6:2}
wget -a $output -nv $url
next=`cat $output`
end_min=${next:3:2}
end_sec=${next:6:2}
alert="no"
sec_dif=$((end_sec-start_sec))
min_dif=$[end_min-start_min]
if [ "$min_dif" -ne "0" ]
then
alert="yes"
else
if [ $sec_dif -gt $gap ] ; then
alert="yes"
fi
fi
if [ $alert == "yes" ]
then
mail -s "$url is taking $sec_dif seconds to respond" "your@email.com" < $output
fi
1Track Back: http://toddlekan.com/blog/2009/07/22/bash_script_for_monitoring_site_responsiveness/trackback
