码迷,mamicode.com
首页 > 其他好文 > 详细

简单日志监控告警小脚本

时间:2016-05-19 19:31:44      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:监控   shell   error   关键词   

#!/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

日志监控工具可参考logstash或zabbix

本文出自 “Just be myself” 博客,请务必保留此出处http://liubin0505star.blog.51cto.com/5550456/1775110

简单日志监控告警小脚本

标签:监控   shell   error   关键词   

原文地址:http://liubin0505star.blog.51cto.com/5550456/1775110

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!