发表于: 2018-05-08 20:02:39

1 761


今天完成的事情:
完成了监控脚本:

#!/bin/bash

logfile=/usr/local/nginx/logs/access.log

start_time=`date -d"$last_minutes minutes ago" +"%H:%M:%S"`

stop_time=`date +"%H:%M:%S"`

tac $logfile | awk -v st="$start_time" -v et="$stop_time" '{t=substr($4,RSTART+14,21);if(t>=st && t<=et) {print $0}}' \

| awk '{print $1}' | sort | uniq -c | sort -nr > $logfile

ip_top=`cat $logfile | head -1 | awk '{print $1}'`

if [[ $ip_top -gt 3  ]];then

  echo "报警nginx" | mail -s '报警nginx' lilong6515@163.com &

fi

编写脚本不停curl请求资源触发报警:

#!/bin/bash

#example:curl.sh http://180.76.148.193 3

usage()

{

 echo "usage: `basename $0` url count"

}

if [ $# -ne 2 ]; then

 usage

 exit 1

fi

for i in `seq 1 $2`;do

 http_code=`curl -o /dev/null -s -w %{http_code} $1`

 echo $1 $http_code

done

结果

 ./curl.sh http://180.76.148.193/ 10

http://180.76.148.193/ 200

http://180.76.148.193/ 200

http://180.76.148.193/ 200

http://180.76.148.193/ 200

http://180.76.148.193/ 200

http://180.76.148.193/ 200

http://180.76.148.193/ 200

http://180.76.148.193/ 200

http://180.76.148.193/ 200

http://180.76.148.193/ 200









遇到的问题:

配置Zabbix,有报警就发邮件通知,这里配置zabbix是

在 示警媒介类型里面用到脚本吗 

如果请求回复正常,发出恢复正常邮件。

这一点感觉,脚本应该进行修改


收获:

Nginx日志实现访问异常报警

http://www.jb51.net/article/107414.htm

nginx 日志和监控

https://blog.csdn.net/agangdi/article/details/41210959

zabbix自定义脚本做监控及自制模板

http://blog.51cto.com/dyc2005/2083880

 Nginx日志管理

https://blog.csdn.net/yuan_xw/article/details/51278623

利用iostat工具监控centos主机磁盘IO

http://www.cnblogs.com/reblue520/p/7255573.html




明天计划的事情:

一步步来,学习知识,完成任务。


返回列表 返回列表
评论

    分享到