打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Linux下利用curl监控web应用状态

curl只返回服务器响应状态,不返回内容,返回200是正常的,其它的不正常,简单的命令如下:

[linuxidc@localhost ~]$ echo `curl -o /dev/null -s -m 10 --connect-timeout 10 -w %{http_code} "http://www.linuxidc.net/index.jsp"`
200
[linuxidc@localhost ~]$ echo `curl -o /dev/null -s -m 10 --connect-timeout 10 -w %{http_code} "http://www.linuxidc.net/index5.jsp"`


404

====================================================

监控机器列表文件:

server.list

server1

server2

server3

建立监控脚本: webstatus.sh

#!/bin/sh
monitor_dir=/home/admin/monitor/
if [ ! -d $monitor_dir ]; then
    mkdir $monitor_dir
fi
cd $monitor_dir
web_stat_log=web.status
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"
   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

主要是利用 curl -o /dev/null -s -m 10 --connect-timeout 10 -w %{http_code} "$url" 返回状态码是否200,如果10s没有返回200状态码,则发警报

最后让linux 定时执行脚本:

crontab -e

*/10 * * * * /home/admin/app/bin/webstatus.sh

这样每隔10分钟就会执行一次


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Ubuntu 10.10下拨号上网 超强的Linux下8021x认证源码
linux shell实用常用命令
监控linux主机的shell脚本
shell脚本:通过shell实现linux用户管理和监控
LINUX 命令执行记录
linux几种快速清空文件内容的方法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服