monitoring_db
#!/bin/bash
# Program:
# Automatic inspection operation system and oracle database.
# History:
# 2016/05/01 Liang Guojun First Release
#
#==============================================================================
# define variable
#==============================================================================
PATH=$PATH:$HOME/bin
export PATH
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
#define ora_healthcheck base directory
ORAH_HOME=/home/oracle/ora_healthcheck
#define Oracle SID
ORAH_DB_SID=orcl
#define tablespace rate
ORAH_TBS_RATE=80
#define alert log size,unit:KB
ORAH_ALERT_SIZE=2097152
ORAH_HOSTNAME=onlinedb
ORAH_BIN=$ORAH_HOME/bin
ORAH_LOG=$ORAH_HOME/logs
ORAH_TMP=$ORAH_HOME/tmp
DATE=`date "+%Y%m%d-%H%M%S"`
rm -f $ORAH_TMP/*
#==============================================================================
# judge oracle SMON process status
#==============================================================================
ps_smon_ori=`ps -ef|grep smon | grep -v grep|grep -v root|grep -v asm|grep -v grid|awk '{print $NF}'`
ps_smon_sid=ora_smon_${ORAH_DB_SID}
if [ "${ps_smon_ori}" = "${ps_smon_sid}" ];then
db_is_down_smon=' '
else
db_is_down_smon='SEND'
fi
#==============================================================================
# judge instance open status
#==============================================================================
instance_status_ori=`sqlplus -S / as sysdba <<EOF
set pagesize 999
set linesize 180
col value format a100
select status from v\\$instance;
exit;
EOF`
instance_status=`echo ${instance_status_ori}|awk -F " " '{print $3}'`
if [ "${instance_status}" = "OPEN" ];then
db_is_down_status=' '
else
db_is_down_status='SEND'
fi
if [[ "${db_is_down_smom}" = "SEND" ]] || [[ "${db_is_down_status}" = "SEND" ]];then
echo "database ${ORAH_HOSTNAME},already Down!" | mutt -s "database ${ORAH_HOSTNAME},already Down!" test@139.com
else
echo "database status is OK!"
fi
#==============================================================================
# execute database tablespace free rate sql
#==============================================================================
sqlplus -S / as sysdba <<EOF > $ORAH_TMP/db_tbs.log
set linesize 160
set pagesize 999
col exclude for a18
col TBS_TOTAL_MB for 9999999
col TBS_USED_MB for 9999999
col TBS_FREE_MB for 9999999
col TBS_RATE for a11
col EXTEND_MAX_MB for 9999999
col EXTEND_FREE_MB for 9999999
col EXTEND_RATE for a11
select a.tablespace_name "excludethis",
round(current_size / 1024 / 1024, 1) TBS_TOTAL_MB,
round((current_size - b.free_bytes) / 1024 / 1024, 1) TBS_USED_MB,
round(b.free_bytes / 1024 / 1024, 1) TBS_FREE_MB,
round(((current_size - b.free_bytes) / current_size) * 100) || '%' TBS_RATE,
round(a.max_size / 1024 / 1024, 1) EXTEND_MAX_MB,
round((a.max_size - (current_size - b.free_bytes)) / 1024 / 1024) EXTEND_FREE_MB,
round(((current_size - b.free_bytes) / a.max_size) * 100) || '%' EXTEND_RATE
from (select tablespace_name,
sum(ddf.bytes) current_size,
sum(case
when ddf.autoextensible = 'YES' THEN
DDF.MAXBYTES
ELSE
DDF.BYTES
END) max_size
from dba_data_files ddf
group by tablespace_name
union
select tablespace_name,
sum(ddf.bytes) current_size,
sum(case
when ddf.autoextensible = 'YES' THEN
DDF.MAXBYTES
ELSE
DDF.BYTES
END) max_size
from dba_temp_files ddf
group by tablespace_name) a,
(select dfs.tablespace_name, sum(dfs.bytes) free_bytes
from dba_free_space dfs
group by dfs.tablespace_name
union
select tfs.tablespace_name, sum(tfs.BYTES_FREE) free_bytes
from v\$TEMP_SPACE_HEADER tfs
group by tfs.tablespace_name) b
where a.tablespace_name = b.tablespace_name(+);
exit;
EOF
#==============================================================================
# judge database tablespace free rate
#==============================================================================
grep -v "excludethis" $ORAH_TMP/db_tbs.log|grep -v "\-\-\-"|grep -v "rows selected">$ORAH_TMP/db_tbs_ori.log
sed -i '/^[[:space:]]*$/d' $ORAH_TMP/db_tbs_ori.log
TBS_RATE=`awk '{print $8}' $ORAH_TMP/db_tbs_ori.log|sed -e "s/%//g"`
TBS_RATE_LENGTH=`cat $ORAH_TMP/db_tbs_ori.log|wc -l`
for ((i=1;i<=${TBS_RATE_LENGTH};i++));do
TBS_RATE_SIZE=`awk '{print $8}' $ORAH_TMP/db_tbs_ori.log|sed -e "s/%//g"|sed -n ${i}p`
TBS_NAME=`awk '{print $1}' $ORAH_TMP/db_tbs_ori.log|sed -e "s/%//g"|sed -n ${i}p`
if [ ${TBS_RATE_SIZE} -gt ${ORAH_TBS_RATE} ];then
sed -n ${i}p $ORAH_TMP/db_tbs_ori.log>>$ORAH_TMP/db_tbs_rate_name.log
else
echo " "
fi
done;
TBS_RATE_NAME=`cat $ORAH_TMP/db_tbs_rate_name.log`
if [ -z "${TBS_RATE_NAME}" ];then
echo "tablespace is OK!"
else
echo "database ${ORAH_HOSTNAME},tablespace(${TBS_NAME}) if full" | mutt -s "database ${ORAH_HOSTNAME},tablespace(${TBS_NAME}) if full" test@139.com
fi
#==============================================================================
# get alert path
#==============================================================================
alertpath_ori=`sqlplus -S / as sysdba <<EOF
set pagesize 999
set linesize 180
col value format a100
select value from v\\$parameter where name='background_dump_dest';
exit;
EOF`
#==============================================================================
# judge alert size if more then 2G backup and touch new
#==============================================================================
alertpath=`echo $alertpath_ori|awk -F " " '{print $3}'`
alert_size=`du -k $alertpath/alert_${ORAH_DB_SID}.log |awk -F " " '{print $1}'`
alert_2g=' '
if [ ${alert_size} -gt ${ORAH_ALERT_SIZE} ];then
mv $alertpath/alert_${ORAH_DB_SID}.log $alertpath/alert_${ORAH_DB_SID}_${DATE}.log && touch $alertpath/alert_$ORAH_DB_SID.log
alert_2g='YES'
else
echo "alert size less then 2G"
fi
#==============================================================================
# judge alert log
#==============================================================================
if_alertout_null=$ORAH_LOG/alert_out.log
if [ "${alert_2g}" = "YES" ];then
cat $alertpath/alert_$ORAH_DB_SID.log> $ORAH_LOG/alert_out.log
lastnum=$(grep -n ".*" $alertpath/alert_$ORAH_DB_SID.log |tail -1|awk -F ":" '{print $1}')
echo ${lastnum} >$ORAH_LOG/alert_num.log
else
if [ ! -s "${if_alertout_null}" ];then
tail -n 100 $alertpath/alert_$ORAH_DB_SID.log> $ORAH_LOG/alert_out.log
lastnum=$(grep -n ".*" $alertpath/alert_$ORAH_DB_SID.log |tail -1|awk -F ":" '{print $1}')
echo ${lastnum} >$ORAH_LOG/alert_num.log
else
firstnum=`cat $ORAH_LOG/alert_num.log`
firstnum=`echo "scale=0;$firstnum+1"|bc`
lastnum=$(grep -n ".*" $alertpath/alert_$ORAH_DB_SID.log |tail -1|awk -F ":" '{print $1}')
echo ${lastnum} >$ORAH_LOG/alert_num.log
sed -n ''"$firstnum","$lastnum"'p' $alertpath/alert_$ORAH_DB_SID.log >$ORAH_LOG/alert_out.log
fi
fi
if_alert_null=`egrep 'ORA-|Heartbeat failed|Deadlock' $ORAH_LOG/alert_out.log`
if [ -z "${if_alert_null}" ];then
echo "alert log is OK!"
else
echo "database ${ORAH_HOSTNAME},alert log has problem" | mutt -s "database ${ORAH_HOSTNAME},alert log has problem" test@139.com
fi
#==============================================================================
# judge CPU
#==============================================================================
cpuuse=`top -b -n2 -p 1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' -v prefix="$prefix" '{ split($1, vs, ","); v=vs[length(vs)]; sub("%", "", v); printf "%s%.1f%%\n", prefix, 100 - v }' |tr -d '%'`
cpunum=`awk -v num1=90 -v num2=$cpuuse 'BEGIN{print(num1>num2)?"0":"1"}'`
if [ $cpunum -eq 0 ];then
echo "CPU is Normal!"
else
echo "host ${ORAH_HOSTNAME},lack of CPU!" | mutt -s "host ${ORAH_HOSTNAME},lack of CPU!" test@139.com
fi
#==============================================================================
# judge Disk
#==============================================================================
diskuse=$(df -hP|grep -v "Filesystem" | grep -c -E \(9[0-9]\%\)\|\(100\%\))
if [ "${diskuse}" -gt 0 ];
then
echo "host ${ORAH_HOSTNAME},disk has full!" | mutt -s "host ${ORAH_HOSTNAME},disk has full!" test@139.com
else
echo "Disk is Normal!"
fi
#==============================================================================
# judge Memory
#==============================================================================
memuse=`free -m|grep Mem|awk '{print ($3-$6-$7)/$2}'`
memnum=`awk -v num1=$memuse -v num2=0.01 'BEGIN{print(num1>num2)?"0":"1"}'`
if [ $memnum -eq 0 ];then
echo "memory is Normal!"
else
echo "host ${ORAH_HOSTNAME},lack of memory!" | mutt -s "host ${ORAH_HOSTNAME},lack of memory!" test@139.com
fi
monitoring_db的更多相关文章
随机推荐
- Ubuntu 16.04 安装 Open Jdk
sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openjdk-7-jdk
- 在Visual Studio Code中使用C#以及.net core
Working with C# Using .NET Core in Visual Studio Code Note: VS Code does not support debugging appli ...
- Springboot如何利用http请求控制器
写好了接口,现在想用postman测试一下这个接口是否正确,想请问怎么传入请求参数?先谢谢了! Springboot如何利用http请求控制器 >> java这个答案描述的挺清楚的:htt ...
- *hiho 1475 - 数组拆分,dp,由N^2降到NlogN
题目链接 描述 小Ho得到了一个数组作为他的新年礼物,他非常喜欢这个数组! 在仔细研究了几天之后,小Ho成功的将这个数组拆成了若干段,并且每段的和都不为0! 现在小Ho希望知道,这样的拆分方法一共有多 ...
- SpringCloud学习笔记(13)----Spring Cloud Netflix之Hystrix断路器的隔离策略
说明 : 1.Hystrix通过舱壁模式来隔离限制依赖的并发量和阻塞扩散 2. Hystrix提供了两种隔离策略:线程池(THREAD)和信号量隔离SEMAPHORE). 1. 线程池隔离(默认策略模 ...
- SpringCloud学习笔记(4)----Spring Cloud Netflix之Eureka的配置
1. Eureka监控配置 Eureka的客户端需要加入依赖 <dependency> <groupId>org.springframework.boot</groupI ...
- 查看Linux 服务器是 32位还是64位的
查看Linux 服务器是 32位还是64位的 getconf LONG_BIT 返回 64 代表就是 64位的: 返回 32 代表就是 32位的:
- git clone 和 git pull 代码无响应
记录一下今天 git 拉代码遇到的一些异常情况: 无论是项目目录下 git pull 还是直接 git clone 都不能正常拉代码: 异常情况1 ssh: connect to host gitee ...
- Maven项目的坐标GroupId和ArtifactId
GroupId和ArtifactId被统称为“坐标”是为了保证项目唯一性而提出的,如果你要把你项目弄到maven本地仓库去,你想要找到你的项目就必须根据这两个id去查找. GroupId一 ...
- ASP.NET-Razor语法03
ASP.NET MVC中使用Razor语法 @{} @{ string s ="super xiao lizi"; @s; // 里面的这个@代表着在页面上输出这个s // 我记 ...