您的位置:首页 > 运维架构

简单日志监控告警小脚本

2016-05-19 17:09 441 查看
#!/bin/bash
#monitor tomcat_log
LOG_DIR=/root/catalina.out
IP=`ifconfig  | grep "inet addr" | grep Bcast | awk -F '[  :]+' '{print $4}'`

tail -Fn0 $LOG_DIR| \
while read line;do
echo $line | grep  -i  -f /root/errorword.txt >/dev/null
if [ $? -eq 0 ];then
echo -e "IP: $IP \n Datetime: $(date) \n Problem: $line" | mail -s "Warning:$IP Log Error " 510264942@qq.com
echo "$IP,$(date),$line" >>/var/log/error_report.log

fi
done
errorword.txt文件里可以存放常见错误关键词如:Out of memory,ERROR,Exception等
另外也可以使用for循环脚本周期性取前几分钟时间段的日志进行错误过滤,或者使用日志监控工具如:logstash或zabbix等。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  监控 shell Error