网站访问状态和超时时间监控报警设置

简介:

由于公司业务比较多,部署的站点也比较多。为了网站安全运行,以防故障发生时能第一时间知晓,特意编写下面监控脚本,对网站访问状态和超时时间进行监控:当code状态为5xx或者访问超时时间大于10s时进行报警。脚本脚本如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@qd-inf-logcollector01 web_monit]$  pwd
/app/script/web_monit
 
[root@qd-inf-logcollector01 web_monit]$ ll
total 12
-rwxr-xr-x 1 root root 870 Oct 12 21:34 http_monit.sh       // 监控脚本
-rwxr-xr-x 1 root root 857 Oct 12 21:25 sms.py              // 短信报警脚本,里面有报警联系人            
-rw-r--r-- 1 root root 377 Oct 12 21:27 weblist.txt         // 监控的网站域名列表
 
[root@qd-inf-logcollector01 web_monit]$  cat  http_monit.sh
#!/bin/sh
weblist= /app/script/web_monit/weblist .txt                      
for  list  in  ` cat  $weblist| grep  -E - v  "#|^$" `               
do
httpcode=`curl -o  /dev/null  -s -w %{http_code}  "$list" `        
httptime=`curl -o  /dev/null  -s -w  "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n"  "$list" | grep  time_total| awk  -F  ":"  '{print $2*1000}' `
if  [ $httpcode = 500 ]||[ $httpcode = 502 ]||[ $httpcode = 503 ]||[ $httpcode = 504 ]
then
    python  /app/script/web_monit/sms .py $list  "$list 访问有误!状态码为$httpcode!请收到报警后尽快查看并处理!"
else
    echo  "$list is checked ok!"
fi
 
if  [ $httptime - ge  10000 ]
then
    python  /app/script/web_monit/sms .py $list  " $list访问超时!超时时间为$httptime毫秒!请收到报警后尽快查看并处理!"
else
   echo  "$list is connect ok!"
fi
done

手动检查网站访问的code状态码

1
2
[root@qd-inf-logcollector01 web_monit]$ curl -o  /dev/null  -s -w %{http_code} http: //www .wang.com
200

手动检查网站访问的超时时间(单位:毫秒,如下网址访问的时间为0.8秒)

1
2
[root@qd-inf-logcollector01 web_monit]$ curl -o  /dev/null  -s -w  "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n"  http: //www .wang.com | grep  time_total| awk  -F  ":"  '{print $2*1000}'
800

网站列表和脚本执行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
[root@qd-inf-logcollector01 web_monit]$ cat  weblist.txt
http: //nop .kevin.cn
http: //ap .kevin.cn
http: //ope .kevin.cn
http: //opr .kevin.cn
http: //www .kevin.cn
http: //kevin .cn
http: //tb .kevin.cn
http: //www .wang.com
https: //www .wang.com
 
http: //doc .kevin.cn
http: //docs .kevin.cn
http: //git .wang.com
http: //monitor .kevin.cn
http: //dash .kevin.cn
 
[root@qd-inf-logcollector01 web_monit]$sh http_monit.sh
http: //nop .kevin.cn is checked ok!
http: //nop .kevin.cn is connect ok!
http: //ap .kevin.cn is checked ok!
http: //ap .kevin.cn is connect ok!
http: //ope .kevin.cn is checked ok!
http: //ope .kevin.cn is connect ok!
http: //opr .kevin.cn is checked ok!
http: //opr .kevin.cn is connect ok!
http: //www .kevin.cn is checked ok!
http: //www .kevin.cn is connect ok!
http: //kevin .cn is checked ok!
http: //kevin .cn is connect ok!
http: //tb .kevin.cn is checked ok!
http: //tb .kevin.cn is connect ok!
http: //www .wang.com is checked ok!
http: //www .wang.com is connect ok!
https: //www .wang.com is checked ok!
https: //www .wang.com is connect ok!
http: //doc .kevin.cn is checked ok!
http: //doc .kevin.cn is connect ok!
http: //docs .kevin.cn is checked ok!
http: //docs .kevin.cn is connect ok!
http: //git .wang.com is checked ok!
http: //git .wang.com is connect ok!
http: //monitor .kevin.cn is checked ok!
http: //monitor .kevin.cn is connect ok!
http: //dash .kevin.cn is checked ok!
http: //dash .kevin.cn is connect ok!

定时监控任务(每两分钟监控一次)

1
2
[root@qd-inf-logcollector01 web_monit]$  crontab  -l
* /2  * * * *  /bin/bash  -x  /app/script/web_monit/http_monit .sh  >  /dev/null  2>&1

简单注意下:比较运算符只有==和!=是用于字符串比较的,不可用于整数比较;整数比较只能使用-eq, -gt这种形式

***************当你发现自己的才华撑不起野心时,就请安静下来学习吧***************

本文转自散尽浮华博客园博客,原文链接:http://www.cnblogs.com/kevingrace/p/7658394.html,如需转载请自行联系原作者
相关文章
|
2月前
|
缓存 监控 网络安全
因服务器时间不同步引起的异常
因服务器时间不同步引起的异常
148 1
|
2月前
|
弹性计算 负载均衡
slb健康检查频率与超时时间
slb健康检查频率与超时时间
101 4
|
5月前
|
JavaScript 前端开发 API
【Azure 应用服务】Azure Function HTTP 触发后, 230秒就超时。而其他方式触发的Function, 执行5分钟后也超时,如何调整超时时间?
【Azure 应用服务】Azure Function HTTP 触发后, 230秒就超时。而其他方式触发的Function, 执行5分钟后也超时,如何调整超时时间?
|
5月前
|
Kubernetes 监控 测试技术
在K8S中,如何查看pod状态的详情? 事件显示cpu不足如何处理?
在K8S中,如何查看pod状态的详情? 事件显示cpu不足如何处理?
|
7月前
|
监控 关系型数据库 MySQL
Flink实现实时异常登陆监控(两秒内多次登陆失败进行异常行为标记)
Flink实现实时异常登陆监控(两秒内多次登陆失败进行异常行为标记)
127 1
|
Windows
连续时间系统的冲激响应和零状态响应
连续时间系统的冲激响应和零状态响应
251 0
|
存储 SQL 数据库
超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。
超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。
729 0
|
数据采集 监控 Linux
一日一技:不用轮询,基于事件监控文件变动
一日一技:不用轮询,基于事件监控文件变动
142 0
如何设置agent上报频率监控间隔时间 - WGCLOUD
在agent/config/application.properties中设置即可
如何设置agent上报频率监控间隔时间 - WGCLOUD

热门文章

最新文章