Oracle数据库监控:报警日志文件及监听

1、下载SendEmail;


2、建立监控脚本:

[oracle@db1 scripts]$ cat check_lsnr_alterlog.sh
#!/bin/sh
####################################
# 2013.05.07 by zhanghui #
####################################
source ~/.bash_profile
#定义变量
v_datetime=`date +"%Y-%m-%d %H:%M:%S"`
#操作系统用户名
v_username='oracle'
#数据库名
v_dbname='xxxdb1'
#Oracle Sid
v_oraclesid='xxxdb11'
#发送者邮箱
v_sendmail=''
#发送者邮箱用户名
v_mailname=''
#发送者邮箱密码
v_password=''
#smtp服务器IP或域名:smtp.163.com
v_smtpserver='113.108.212.80'
#接收者邮件,如果是多个用空间分开
v_receivemail=' '
#路径
v_path="/home/${v_username}/scripts"
#Oracle报警日志文件位置,10g与11g位置不同
v_alertlogpath="${ORACLE_BASE}/diag/rdbms/${v_dbname}/${v_oraclesid}/trace"
#####Oracle 报警日志文件监控代码开始#####
if [ -f ${v_alertlogpath}/alert_${v_oraclesid}.log ] ; then
cat ${v_alertlogpath}/alert_${v_oraclesid}.log > ${v_path}/alert_work_${v_oraclesid}.log
> ${v_alertlogpath}/alert_${v_oraclesid}.log
cat ${v_path}/alert_work_${v_oraclesid}.log >> ${v_alertlogpath}/alert_${v_oraclesid}.history
grep -E ^ORA-\|Reconfig\|abort\|Shut\|Start\|error\|Instance\|Suspend\|Resuming\|Deadlock ${v_path}/alert_work_${v_oraclesid}.log > ${v_path}/alert_${v_oraclesid}.err
fi
if [ `cat ${v_path}/alert_${v_oraclesid}.err|wc -l` -gt 0 ] ; then
${v_path}/sendEmail -f ${v_sendmail} -t ${v_receivemail} -s ${v_smtpserver} -u "${v_dbname} ERROR alert_${v_oraclesid}.LOG (${v_datetime})" -xu ${v_mailname} -xp ${v_password} -o message-content-type=text -o message-charset=UTF-8 message-file=${v_path}/alert_work_${v_oraclesid}.log -l ${v_path}/lsnr_alterlog_sendmail.log
fi
rm -f ${v_path}/alert_${v_oraclesid}.err
rm -f ${v_path}/alert_work_${v_oraclesid}.log
#####Oracle 报警日志文件监控代码结束#####
#####Oracle LISTENER 监控代码开始#####
rm -f ${v_path}/lsnr_${v_oraclesid}.exist
ps -ef|grep -i LISTENER|grep -v grep > ${v_path}/lsnr_${v_oraclesid}.exist
if [ -s ${v_path}/lsnr_${v_oraclesid}.exist ] ;then
echo
else
${v_path}/sendEmail -f ${v_sendmail} -t ${v_receivemail} -s ${v_smtpserver} -u "${v_oraclesid} LISTENER process down (${v_datetime})" -xu ${v_mailname} -xp ${v_password} -m "Check oracle LISTENER" -l ${v_path}/lsnr_alterlog_sendmail.log
fi
#####Oracle LISTENER 监控代码结束#####


3、配置crontab,每一分钟执行一次

[oracle@db1 scripts]$ crontab -l
#oracle listener and alterlog check
*/1 * * * * /home/oracle/scripts/check_lsnr_alterlog.sh >/dev/null 2>&1


你可能感兴趣的:(oracle,监控)