免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 7144 | 回复: 14
打印 上一主题 下一主题

关于监控oracle的alert文件的问题 [原创] [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-06-16 14:31 |只看该作者 |倒序浏览
正好有人讨论监控oracle的alert问题.

我写了几个脚本. 拿出来大家讨论

论坛徽章:
0
2 [报告]
发表于 2004-06-16 14:36 |只看该作者

关于监控oracle的alert文件的问题 [原创]

思路一, 使用sed的模式空间和保持空间处理获取特定关键字上面行的问题

以下未sed脚本文件, 保存成scr1 (注意, 清除每行末尾的空格)
自己改一下第一个时间字段


  1. /^Wed Jan.*$/ {
  2. x
  3. /ORA/b go
  4. d
  5. x
  6. d
  7. b
  8. :go
  9. p
  10. d
  11. x
  12. d
  13. }

  14. /^.*$/ {
  15. H
  16. }
复制代码


使用以下命令处理alert文件
  1. sed -f scr1 alert*.log
复制代码

论坛徽章:
0
3 [报告]
发表于 2004-06-16 14:40 |只看该作者

关于监控oracle的alert文件的问题 [原创]

思路2,使用awk等进行shell编程

下面这个版本是集中监控的版本.
程序运行在各个oracle主机上(后台方式), 处理结果放到集中监控的机器上,
在监控机器上可以用tail命令查看结果.

已经在生产环境中运行半年了. 小bug, 不影响使用
环境: oracle 9i RAC (4node) for hpux


  1. #!/usr/bin/ksh
  2. # #############################################################################
  3. # purpose  : auto check oracle alert file
  4. # filename : check.sh
  5. # author   : dntadm2 (steven)
  6. # version  : 2004/03/04 print line num can modify like this :
  7. #                       echo `sed -n '/date/=;$=' log` |sed 's/ /:/'
  8. # version  : 2004/02/25 fix bugs (trap a NULL i value)
  9. # version  : 2004/02/13 send error to a centrala host to display
  10. # version  : 2004/02/10 fix bugs (last line problem)
  11. #                       fix bugs (cannot compare with * in filename by create datetime)
  12. #                       fix bugs (chinese date)
  13. #                       fix bugs for linux & hpux
  14. # version  : 2004/01/30 modified u can interrupt it and then continue it
  15. #                       modified this script to run with oracle RAC
  16. # version  : 2004/01/20 first release
  17. # #############################################################################

  18. unset LANG
  19. unset LANGUAGE

  20. localhost=`hostname`
  21. mon_host="center_3"
  22. mon_file="../../../data/syslog/alert.log"
  23. orasid=`grep -v ^# /etc/oratab |sort -u |tail -1 |cut -d: -f1`
  24. orahome=`grep -v ^# /etc/oratab |sort -u |tail -1 |cut -d: -f2`
  25. alertfile=$orahome/../../admin/$orasid/bdump/alert_${orasid}.log
  26. tagfile=dnt_tag
  27. day=`date |cut -c1-10`
  28. first=`awk -v var1="$day" '$0 ~ var1 {print NR}' $alertfile |head -1`
  29. begin_num=`wc -l $alertfile |sed 's/^  *//' |cut -d" " -f1` # an all-purpose for linux and hpux

  30. if [[ -z $first ]]; then
  31. echo "no log for today"
  32. fi

  33. while true
  34. do
  35.   day=`date |cut -c1-10`
  36.   output=/tmp/check_alert.$$

  37.   if [[ ! -f $tagfile ]]; then
  38.     #echo "new a file"
  39.     unset IFS
  40.     line_num=`echo \`cat $alertfile |awk -v var1="$day" '$0 ~ var1 {print NR} END {print NR}'\` |sed 's/ /:/g'`
  41.     # echo $line_num
  42.     touch $tagfile
  43.     chmod 666 $tagfile
  44.     begin_num=${line_num%%:*}
  45.     line_num=${line_num#*:}
  46.   elif [[ $alertfile -nt $tagfile ]]; then
  47.     #echo " alert is newer than tagfile"
  48.     unset IFS
  49.     line_num=`echo \`cat $alertfile |awk -v var1="$day" '$0 ~ var1 {print NR} END {print NR}'\` |sed 's/ /:/g'`
  50.     # echo $line_num
  51.     touch $tagfile
  52.     chmod 666 $tagfile
  53.     line_num=${line_num##*$begin_num}
  54.     begin_num=$((begin_num+1))
  55.     line_num=${line_num##*$begin_num:}
  56.   else
  57.     #echo "alert file is older than tagfile"
  58.     #echo ".\c"
  59.     sleep 30
  60.     #trap 'wait; rm -fr $tagfile; exit 2' 2
  61.     continue
  62.   fi

  63.   export IFS=:
  64.   # echo
  65.   # echo "begin_num="$begin_num
  66.   # echo "line_num="$line_num
  67.   for i in $line_num
  68.   do
  69.     if [ "$i" -eq "" ]; then
  70.       continue
  71.     fi
  72.     if [[ $i = ${line_num##*:} ]]; then
  73.       sed -n "$begin_num,${i}p" $alertfile |grep ^ORA- 1>/dev/null 2>&1
  74.       if [[ $? = 0 ]]; then
  75.         # echo "$begin_num to $i"
  76.         echo "=====" > $output
  77.         sed -n "$begin_num,${i}p" $alertfile |sed "s/^/$localhost: /" >> $output
  78.       fi
  79.     else
  80.       sed -n "$begin_num,$((i-1))p" $alertfile |grep ^ORA- 1>/dev/null 2>&1
  81.       if [[ $? = 0 ]]; then
  82.         # echo "$begin_num to $i"
  83.         echo "=====" > $output
  84.         sed -n "$begin_num,$((i-1))p" $alertfile |sed "s/^/$localhost: /" >> $output
  85.       fi
  86.     fi

  87.     if [ -f $output ]; then
  88.       while read sline; do
  89.         sline="'"$sline"'"
  90.         remsh $mon_host -n "echo $sline >> $mon_file"
  91.       done < $output
  92.       /sbin/rm -f $output
  93.     fi

  94.     begin_num=$i
  95.     # echo $begin_num
  96.   done
  97. done

复制代码

论坛徽章:
0
4 [报告]
发表于 2004-09-13 22:12 |只看该作者

关于监控oracle的alert文件的问题 [原创]

这样的东西竟然回帖? 真伤心
大家没有这样的需求吗?

论坛徽章:
0
5 [报告]
发表于 2004-09-14 08:43 |只看该作者

关于监控oracle的alert文件的问题 [原创]

好东西,顶.

论坛徽章:
0
6 [报告]
发表于 2004-09-14 10:43 |只看该作者

关于监控oracle的alert文件的问题 [原创]

顶先,呵呵!

论坛徽章:
0
7 [报告]
发表于 2004-11-16 16:53 |只看该作者

关于监控oracle的alert文件的问题 [原创]

有人看就顶上来

论坛徽章:
0
8 [报告]
发表于 2004-11-17 11:27 |只看该作者

关于监控oracle的alert文件的问题 [原创]

太太太感谢了,自己写了一个太简单了,这个根本不用改就能直接拿来用了。不过,我这里还有很多系统用8i,还要改下,呵。
感谢

论坛徽章:
0
9 [报告]
发表于 2004-11-17 11:39 |只看该作者

关于监控oracle的alert文件的问题 [原创]

我们这里曾经出现过系统当机后,oracle起不起来,oracle工程师排障后判断是有人对底层的alert文件进行监控导致,搂住能说说是什么原因吗?

论坛徽章:
0
10 [报告]
发表于 2004-11-17 12:06 |只看该作者

关于监控oracle的alert文件的问题 [原创]

原帖由 "hawkli" 发表:
太太太感谢了,自己写了一个太简单了,这个根本不用改就能直接拿来用了。不过,我这里还有很多系统用8i,还要改下,呵。
感谢


原来真的有人需要. hoho. 这个帖子沉了半年了吧. 贴一个新版本. 监控效率提高n倍

  1. #!/usr/bin/ksh
  2. # #############################################################################
  3. # purpose  : auto check oracle alert file
  4. # filename : checkalert.sh
  5. # author   : steven
  6. # date     : 2004/10/23
  7. # #############################################################################

  8. HOSTNAME=`hostname`
  9. BASEDIR=/var/tmp
  10. MONHOST="xxxx"
  11. MONFILE="../../../data/syslog/alert.log"
  12. TAGFILE=$BASEDIR/alertcheck_tagfile
  13. STATFILE=$BASEDIR/alertcheck_statusfile
  14. OUTPUT=$BASEDIR/alertcheck_outputfile
  15. TMPFILE=$BASEDIR/alertcheck_tmpfile
  16. ALERTFILE=/data11/bak/bdump/sid.log

  17. CUR=`ll $ALERTFILE |awk '{print $5}'`
  18. if [ ! -f $STATFILE ] || [ `cat $STATFILE` -gt $CUR ]; then
  19.   ll $ALERTFILE |awk '{print $5}' > $STATFILE
  20. fi

  21. if [ ! -f $TAGFILE ]; then
  22.   touch $TAGFILE
  23. fi

  24. if [ ! -f $OUTPUT ]; then
  25.   touch $OUTPUT
  26. fi

  27. CNT=`cat $STATFILE`

  28. while true ; do
  29.   sleep 3
  30.   if [ $ALERTFILE -nt $TAGFILE ]; then
  31.     NEWSTAT=`ll $ALERTFILE |awk '{print $5}'`
  32.     dd if=$ALERTFILE of=$TMPFILE bs=1 skip=$CNT 1>/dev/null 2>&1
  33.     CHECKSTAT=`ll $ALERTFILE |awk '{print $5}'`
  34.     if [ ! $NEWSTAT -eq $CHECKSTAT ]; then
  35.       continue
  36.     fi
  37.     touch $TAGFILE
  38.     LINE=`cat -n $TMPFILE |awk '/... ... .. ..:..:.. 200./ {print $1} END { print NR }' |xargs`
  39.     echo $LINE |awk '{printf("%s %s\n",$(NF-1),$NF)}' |read L1 L2
  40.     if [ $L1 -eq $L2 ]; then
  41.       LINE=${LINE% *}
  42.       CNT=$((NEWSTAT-25))
  43.     else
  44.       LINE=${LINE% *}" $((L2+1))"
  45.       CNT=$NEWSTAT
  46.     fi
  47.     echo $CNT > $STATFILE

  48.     BEGIN=1
  49.     for i in $LINE ; do
  50.       if [ ! $((i-1)) -gt 1 ]; then
  51.         continue
  52.       fi
  53.       sed -n "$BEGIN,$((i-1))p" $TMPFILE |\
  54.         grep -i -e Reconfig -e Start -e Shut -e ^ORA -e error -e Instance 1>/dev/null 2>&1
  55.       if [ $? -eq 0 ]; then
  56.         sed -n "$BEGIN,$((i-1))p" $TMPFILE |sed "s/^/$HOSTNAME: /" >> $OUTPUT
  57.       fi
  58.       BEGIN=$i
  59.     done

  60.     while read sline; do
  61.       sline="'"$sline"'"
  62.       remsh $MONHOST -n "echo $sline >> $MONFILE"
  63.     done < $OUTPUT

  64. #    > $TMPFILE
  65.     > $OUTPUT

  66.   else
  67.     continue
  68.   fi
  69. done
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP