linux下利用curl监控web应用状态
2012-04-20 11:58
549 查看
简单用curl进行应用的监控
监控机器列表文件:
server.list
建立监控脚本: webstatus.sh
#!/bin/sh
monitor_dir=/home/admin/monitor/ #Log记录目录
if [ ! -d $monitor_dir ]; then
mkdir $monitor_dir
fi
cd $monitor_dir
web_stat_log=web.status #Log文件
if [ ! -f $web_stat_log ]; then
touch $web_stat_log
fi
server_list_file=server.list #读取文件列表
if [ ! -f $server_list_file ]; then
echo "`date '+%Y-%m-%d %H:%M:%S'` ERROR:$server_list_file NOT exists!" >>$web_stat_log
exit 1
fi
#total=`wc -l $server_list_file|awk '{print $1}'`
for website in `cat $server_list_file`
do
url="http://$website/app.htm" #Url地址,从server.list 里读取
server_status_code=`curl -o /dev/null -s -m 10 --connect-timeout 10 -w %{http_code} "$url"`
if [ "$server_status_code" = "200" ]; then
echo "`date '+%Y-%m-%d %H:%M:%S'` visit $website status code 200 OK" >>$web_stat_log
else
echo "`date '+%Y-%m-%d %H:%M:%S'` visit $website error!!! server can't connect at 10s or stop response at 10 s, send alerm sms ..." >>$web_stat_log
echo "!app alarm @136xxxxxxxx server:$website can't connect at 10s or stop response at 10s ..." | nc smsserver port &
fi
done
exit 0
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
crontab -e 定时执行脚本。
监控机器列表文件:
server.list
建立监控脚本: webstatus.sh
#!/bin/sh
monitor_dir=/home/admin/monitor/ #Log记录目录
if [ ! -d $monitor_dir ]; then
mkdir $monitor_dir
fi
cd $monitor_dir
web_stat_log=web.status #Log文件
if [ ! -f $web_stat_log ]; then
touch $web_stat_log
fi
server_list_file=server.list #读取文件列表
if [ ! -f $server_list_file ]; then
echo "`date '+%Y-%m-%d %H:%M:%S'` ERROR:$server_list_file NOT exists!" >>$web_stat_log
exit 1
fi
#total=`wc -l $server_list_file|awk '{print $1}'`
for website in `cat $server_list_file`
do
url="http://$website/app.htm" #Url地址,从server.list 里读取
server_status_code=`curl -o /dev/null -s -m 10 --connect-timeout 10 -w %{http_code} "$url"`
if [ "$server_status_code" = "200" ]; then
echo "`date '+%Y-%m-%d %H:%M:%S'` visit $website status code 200 OK" >>$web_stat_log
else
echo "`date '+%Y-%m-%d %H:%M:%S'` visit $website error!!! server can't connect at 10s or stop response at 10 s, send alerm sms ..." >>$web_stat_log
echo "!app alarm @136xxxxxxxx server:$website can't connect at 10s or stop response at 10s ..." | nc smsserver port &
fi
done
exit 0
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
crontab -e 定时执行脚本。
相关文章推荐
- linux下利用curl监控web应用状态
- 利用curl监控web返回状态码监控web service
- shell+curl监控网站页面(域名访问状态),并利用sedemail发送邮件
- linux下利用curl监控网页shell脚本
- 利用RATF框架实现web状态的监控
- linux下利用curl监控网页shell脚本
- shell+curl监控网站页面(域名访问状态),并利用sendemail发送邮件
- linux应用服务状态——脚本监控方法
- linux下wc和netstat监控tomcat(web)应用的情况
- 利用JMX监控Websphere Application Server6.1的J2EE应用服务运行状态
- 使用curl脚本监控web服务状态
- Linux利用curl库快速开发http应用
- linux下利用curl监控网页shell脚本
- 利用接口测试框架实现web状态的监控
- [转载][翻译] 利用JSF、SpringFramework和Hibernate构建Web应用的实例讲述
- 监控Linux环境下JVM应用内存的两种方法
- 在linux下,利用gSoap开发Web Service C/C++客户端
- linux安装使用jprofiler6分析服务器应用状态
- linux下利用JMX监控Tomcat
- 电信屏蔽了80端口,利用80端口映射解决web网站应用发布问题