oracle 檢測指令碼on linux
#!/bin/bash
# This script is used for monitoring database servers including the following items daily
# 1 Disk space usage;
# 2 Database space usage;
# 2.1 ASM_disgroup USAGE;
# 2.2 Data size status and tablespace usage and Top 5 wait event within 7 days;
# 2.3 Database Error log info;
#
#Author:Ben
#Create Date: 2011-02-18
#Create monitor log directory:
SCRIPT_BASE=/home/oracle/monitor
if [ ! -d $SCRIPT_BASE ]; then
mkdir $SCRIPT_BASE
fi
LOGDIR=$SCRIPT_BASE/log
if [ ! -d $LOGDIR ]; then
mkdir $LOGDIR
fi
DATE=`date +%Y-%m-%d`
Time=`date +%X`
LOG=$LOGDIR/$DATE.log
Servername=`hostname`
echo "">$LOG
echo "========$Servername monitor log is as below=======">>$LOG
echo "">>$LOG
echo "========Monitor time is $DATE-$Time.======= ">>$LOG
####### 1 Check the filesystem usage and log if usage is over 90%###########
echo ''>>$LOG
echo '1 Filesystem usage:'>>$LOG
Filesystem=`df -h|awk '{print $6}'|grep -v Filesystem|grep -v none|grep -v ":/"`
for i in `df -h|awk '{print $5}'|grep -v Use|grep -v "/"|cut -d% -f1`
do
if [ $i -gt 90 ]; then
echo " Warning:The usage of $Filesystem has been $i%">>$LOG
fi
done
echo " `df -h`">>$LOG
echo ''>>$LOG
####### 2 Check database space usage###########
###2.1 ASM###
echo ''>>$LOG
echo "2 Database space usage:">>$LOG
oraclesidnum=`ps -ef|grep pmon|grep "_"|awk '{print $8}'|cut -d_ -f3|grep -v "+"|wc -l` ## count the instance number
oracle_home=`grep -v ^[#] /etc/oratab|grep -v '^$' |grep -v '+'|grep -v '*'|awk -F : '{print $2}'|head -n 1` ## get ORACLE_HOME
####Check if use ASM
asm=`ps -ef|grep pmon|grep "_"|awk '{print $8}'|cut -d_ -f3|grep "+"`
if [ "$asm" = "" ];then
echo " oracle storage is not using ASM!">>$LOG
else
oracle_sid_asm=`ps -ef|grep pmon|grep "_"|awk '{print $8}'|cut -d_ -f3|grep -v "+"|head -n 1` ## get ORACLE_SID
export ORACLE_SID=$oracle_sid_asm
export ORACLE_HOME=$oracle_home
export PATH=$oracle_home/bin:$PATH
echo ''>>$LOG
echo " 2.1 ASM_DISGROUP usage:">>$LOG
sqlplus -s "/ as sysdba"
<
spool '$LOG' app
set linesize 180
set feedback off
select GROUP_NUMBER,NAME,TOTAL_MB/1024 G,FREE_MB/1024 AG from V$ASM_DISKGROUP;
spool off
exit
EOF
fi
####Data size status and tablespace usage and Top 5 event ####
echo ''>>$LOG
echo " 2.2 Data size status and tablespace usage and top 5 event">>$LOG
#Ora_version=`grep "Oracle Database" $LOG|awk '{print $3}|cut -dg -f1'`
for i in `ps -ef|grep pmon|grep "_"|awk '{print $8}'|cut -d_ -f3|grep -v "+"`
do
export ORACLE_SID=$i
export ORACLE_HOME=$oracle_home
export PATH=$oracle_home/bin:$PATH
Sdate=`date +%b%d%R`
spoolfile=$LOGDIR/$Sdate.$i.txt
echo " Instance $i:">>$LOG
sqlplus -s "/ as sysdba"
<
spool '$LOG' app
set linesize 180
set feedback off
col VALUE for a60
col file_name for a60
col event_name for a30
show parameter db_name;
SELECT VALUE FROM v$parameter WHERE name like '%background_dump_dest%';
select * from v$flash_recovery_area_usage;
select thread#,max(sequence#) from v$archived_log group by thread#;
select dbf.AllocateSize,
de.UsedSize,
(de.UsedSize/dbf.AllocateSize) * 100 Per_Used,
(dbf.AllocateSize-de.UsedSize) FreeSize
from
(SELECT
SUM(bytes)/1024/1024/1024 AllocateSize
FROM dba_data_files files) dbf,
(SELECT SUM(bytes)/1024/1024/1024 UsedSize
FROM dba_extents) de;
SELECT
D.TABLESPACE_NAME,SPACE "SUM_SPACE(M)",
SPACE-NVL(FREE_SPACE,0) "USED_SPACE(M)",
FREE_SPACE "FREE_SPACE(M)",
ROUND((1-NVL(FREE_SPACE,0)/SPACE)*100,2) "USED_RATE(%)"
FROM
(SELECT
TABLESPACE_NAME,
ROUND(SUM(BYTES)/(1024*1024),2) SPACE,
SUM(BLOCKS) BLOCKS
FROM DBA_DATA_FILES
GROUP BY TABLESPACE_NAME) D,
(SELECT
TABLESPACE_NAME,
ROUND(SUM(BYTES)/(1024*1024),2) FREE_SPACE
FROM DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)
order by TABLESPACE_NAME;
SELECT
D.TABLESPACE_NAME,SPACE1 "Total",SPACE "SUM_SPACE(M)",
SPACE-NVL(FREE_SPACE,1) "USED_SPACE(M)",
SPACE1-(SPACE-NVL(FREE_SPACE,0)) "FREE_SPACE(M)",
ROUND((SPACE-NVL(FREE_SPACE,1))/SPACE1*100,2) "USED_RATE(%)"
FROM
(SELECT
TABLESPACE_NAME,
ROUND(SUM(decode(MAXBYTES,0,BYTES,MAXBYTES))/(1024*1024),2) SPACE1,
ROUND(SUM(BYTES)/(1024*1024),2) SPACE
FROM DBA_DATA_FILES
GROUP BY TABLESPACE_NAME ) D,
(SELECT
TABLESPACE_NAME,
ROUND(SUM(BYTES)/(1024*1024),2) FREE_SPACE
FROM DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)
order by TABLESPACE_NAME;
select Day, Event_name, Total_wait from (
select day, event_name, sum(event_time_waited) total_wait,
row_number() over (partition by day order by sum(event_time_waited) desc) rn from (
SELECT to_date(to_char(begin_interval_time,'dd/mm/yyyy'),'dd/mm/yyyy') day,s.begin_interval_time, m.*
FROM (SELECT ee.instance_number, ee.snap_id, ee.event_name,
ROUND (ee.event_time_waited/1000000) event_time_waited,
ee.total_waits,
ROUND ((ee.event_time_waited * 100)/et.total_time_waited,
1
) pct,
ROUND ((ee.event_time_waited/ee.total_waits)/1000
) avg_wait
FROM (SELECT ee1.instance_number, ee1.snap_id, ee1.event_name,
(ee1.time_waited_micro-ee2.time_waited_micro) event_time_waited,
(ee1.total_waits-ee2.total_waits) total_waits
FROM dba_hist_system_event ee1 JOIN dba_hist_system_event ee2
ON ee1.snap_id = ee2.snap_id + 1
AND ee1.instance_number = ee2.instance_number
AND ee1.event_id = ee2.event_id
AND ee1.wait_class_id <> 2723168908
AND (ee1.time_waited_micro-ee2.time_waited_micro) > 0
UNION
SELECT st1.instance_number, st1.snap_id,
st1.stat_name event_name,
(st1.VALUE-st2.VALUE) event_time_waited,
1 total_waits
FROM dba_hist_sys_time_model st1 JOIN dba_hist_sys_time_model st2
ON st1.instance_number = st2.instance_number
AND st1.snap_id = st2.snap_id + 1
AND st1.stat_id = st2.stat_id
AND st1.stat_name = 'DB CPU'
AND (st1.VALUE-st2.VALUE) > 0
) ee
JOIN
(SELECT et1.instance_number, et1.snap_id,
(et1.VALUE-et2.VALUE) total_time_waited
FROM dba_hist_sys_time_model et1 JOIN dba_hist_sys_time_model et2
ON et1.snap_id = et2.snap_id + 1
AND et1.instance_number = et2.instance_number
AND et1.stat_id = et2.stat_id
AND et1.stat_name = 'DB time'
AND (et1.VALUE-et2.VALUE) > 0
) et
ON ee.instance_number = et.instance_number
AND ee.snap_id = et.snap_id
) m
JOIN
dba_hist_snapshot s ON m.snap_id = s.snap_id
) group by day ,event_name
order by day desc, total_wait desc
)where rn < 6;
spool off
exit
dbsize
echo ''>>$LOG
##############Check alert log######
echo ''>>$LOG
echo " 2.3 Error from alert.log file:">>$LOG
echo " Error from Instance $i: ">>$LOG
dbname=`grep 'db_name' $spoolfile|awk '{print $3}'`
Bdumppath=`grep "/$dbname/" $spoolfile`
cd $Bdumppath
Alertfile=alert_$i.log
Todate=`date +'%b'` ##get abbreviated month name
Errmsg=`grep "$Todate" $Alertfile|grep "ORA-" `
if [ !-n $Errmsg ];then
echo "There is no error in instance $i">>$LOG
else
echo "Error message is:">>$LOG
echo "$Errmsg">>$LOG
echo ''>>$LOG
fi
rm -rf $spoolfile
done
cd $LOGDIR
find . -name '*.log' -mtime +7 -exec rm -rf {} ;
#find . -name '*.txt' -mtime +3 -exec rm -rf {} ;
#######Mail to Ben
cat $LOG |mail -s "Seatadvisor: $Servername Daily Monitor Result" jerry.mao@bestit.com
[@more@]來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9907339/viewspace-1048599/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 檢視ORACLE AS 埠指令碼Oracle指令碼
- (轉)ORACLE 巡檢指令碼Oracle指令碼
- 巡檢指令碼OS+Oracle指令碼Oracle
- oracle linux rman 指令碼OracleLinux指令碼
- 欄位型別檢測指令碼型別指令碼
- 檢測mysql狀態的指令碼MySql指令碼
- Tomcat自動檢測和重啟指令碼(Linux)薦Tomcat指令碼Linux
- Linux系統檢查指令碼Linux指令碼
- 【SCN】Oracle檢查scn值指令碼Oracle指令碼
- oracle 巡檢指令碼(自動化)Oracle指令碼
- oracle、filesystem、backup日常巡檢指令碼Oracle指令碼
- Linux埠探測指令碼Linux指令碼
- Python指令碼檢測笑臉漏洞Python指令碼
- oracle for linux 備份指令碼OracleLinux指令碼
- Linux 系統健康巡檢指令碼Linux指令碼
- Oracle運維指令碼-巡檢(RAC版)Oracle運維指令碼
- oracle 檢視隱含引數指令碼Oracle指令碼
- ORACLE提供檢驗RAC是否健康指令碼Oracle指令碼
- Oracle 10G RAC巡檢指令碼Oracle 10g指令碼
- (轉):oracle、filesystem、backup日常巡檢指令碼Oracle指令碼
- 【管理】Oracle 常用的V$ 檢視指令碼Oracle指令碼
- haproxy狀態檢測指令碼(完成高可用)指令碼
- CentOS 6 系統優化檢測指令碼CentOS優化指令碼
- python檢測圖片是否存在指令碼Python指令碼
- Linux檢視網路流量的指令碼Linux指令碼
- 使用MD5的檢測方法,shell指令碼實現linux系統檔案完整性檢測指令碼Linux
- Oracle運維指令碼-巡檢(單機版)Oracle運維指令碼
- 【SCRIPT】Oracle日常巡檢指令碼通用版Oracle指令碼
- oracle 資料庫效能健康檢查指令碼Oracle資料庫指令碼
- 通過shell指令碼檢測MySQL服務資訊指令碼MySql
- Linux 下oracle自啟動指令碼LinuxOracle指令碼
- unix、linux oracle rman匯出指令碼LinuxOracle指令碼
- linux下oracle熱備份指令碼LinuxOracle指令碼
- Linux基礎服務巡檢指令碼模板Linux指令碼
- Linux檢視佔用swap的程式指令碼Linux指令碼
- (轉)oracle 資料庫效能健康檢查指令碼Oracle資料庫指令碼
- 【Oracle】 檢查log fie sysnc 等待事件的指令碼Oracle事件指令碼
- Linux系統效能測試指令碼(unixbenchnmon)Linux指令碼