AIX主機監控指令碼

來源:互聯網
上載者:User

AIX主機監控指令碼 該指令碼包含對主機的CPU、MEMROY、IO、NET、HACMP、ERROR REPORT監控。 對資料庫的資料表空間、JOB、ALERT LOG等的監控。  001#!/bin/sh002 003# 首先載入設定檔,如果設定檔不存在,則報錯退出004SOURCE=$HOME/config/config005check_source()006{007if [ -r $SOURCE ]; then008. $SOURCE009else010echo "$(basename $0): Cannot locate the default setting file."011exit 1012fi013}014 015# 定義報表頭016report_header()017{018HOSTIP=$(ifconfig -a | sed -n '2p' |awk '{print $2}')019HOSTNAME=$(hostname)020USER=`who am i | cut -d " " -f1`021cat<Hostname: $HOSTNAME Server: $HOSTIP022User: $USER Time: $(date +%Y'-'%m'-'%d' '%H':'%M':'%S)023 024SYSTEM CHECK REPORT025===================026 027!028}029 030# 定義記錄檔存放的目錄和記錄檔名,將目前使用者目錄設定為LOG_PATH031LOG_PATH=$(echo $HOME)032LOG_FILE=$LOG_PATH/log`date +%Y%m%d%H%M%S`033 034# 備份曆史檔案035cd $LOG_PATH036test -f log2007*037if [ "$?" -eq 0 ];then038mv $LOG_PATH/log2007* $LOG_PATH/niyl/ >/dev/null 2>&1039else040:041fi042 043#define temp directory ,if not exist,create temp directory first.044TEMP_PATH=$LOG_PATH/temp045if [ -d $TEMP_PATH ];then046:047else048mkdir $TEMP_PATH049fi050 051# 載入環境設定052check_source053 054# 輸出報表頭資訊055report_header >>$LOG_FILE056 057 058# 檢查 CPU的使用方式059echo "***************************************** Check CPU *****************************************">>$LOG_FILE060vmstat 1 10 | awk '{print $0;if($1 ~ /^[0-9].*/) (totalcpu+=$16);(avecpu=100-totalcpu/10)}; END {print "The average usage of cpu is :"avecpu}' >$TEMP_PATH/cpu_info061 062cat $TEMP_PATH/cpu_info >>$LOG_FILE063 064cpu_used_pct=`cat $TEMP_PATH/cpu_info | grep "The average usage of cpu is" |awk -F ":" '{print $2}' `065if [ "$cpu_used_pct" -gt "$CPU_VALUE" ] ; then066echo "LOG-Warnning:`date +%Y'-'%m'-'%d' '%H':'%M':'%S`, The CPU usage is up to $cpu_used_pct%. Please check the system.">>$LOG_FILE067else068echo " The CPU load is OK!!">>$LOG_FILE069fi070 071 072# 記憶體使用量監控,包括交換區的使用方式監控073echo >>$LOG_FILE074echo >>$LOG_FILE075echo "***************************************** check memory useage *****************************************">>$LOG_FILE076cat $TEMP_PATH/cpu_info | awk '{print $0;if($1 ~ /^[0-9].*/) (totalpi+=$6)(totalpo+=$7)};077END {if(totalpi<10 && totalpo<10) print " The memory usage  is OK!!"; if(totalpi>10 || totalpo>10) print "The memory pagein  and pageout is to high,Please check the usage of the memory!"} '>>$LOG_FILE078 079 080# 檢查磁碟空間.081echo >>$LOG_FILE082echo >>$LOG_FILE083echo "***************************************** check disk space *****************************************">>$LOG_FILE084df -k >>$LOG_FILE085df -k |grep -v proc |grep -v Filesystem |awk '{x=1*$4}{print $1","$2","$3","$4","$5","$6","$7}'>$TEMP_PATH/disk_info086 087cat $TEMP_PATH/disk_info | grep -v '^#' | while read line088do089item1=$(echo $line | awk -F ',' '{print $1}')090item2=$(echo $line | awk -F ',' '{print $2}')091item3=$(echo $line | awk -F ',' '{print $3}')092item4=$(echo $line | awk -F ',' '{print $4}' |awk -F '%' '{print $1}')093item5=$(echo $line | awk -F ',' '{print $5}')094item6=$(echo $line | awk -F ',' '{print $6}')095item7=$(echo $line | awk -F ',' '{print $7}')096if [ "$item4" -gt "$DISK_VALUE" ]; then097echo "LOG-Warnning: `date +%Y'-'%m'-'%d' '%H':'%M':'%S`, $item7 is not have enough space ,please check." >>$LOG_FILE098else099echo " The space of disk $item7 is OK!!" >>$LOG_FILE100fi101done102 103#104# 檢查磁碟的io進行監控,iostat105#106echo >>$LOG_FILE107echo >>$LOG_FILE108echo "***************************************** check iostat *****************************************">>$LOG_FILE109iostat 1 3 >>$LOG_FILE110 111# 對網路流量進行監控112echo >>$LOG_FILE113echo >>$LOG_FILE114echo "***************************************** check netstat *****************************************">>$LOG_FILE115netstat -i >>$LOG_FILE116 117# Check the oracle background processes .118echo >>$LOG_FILE119echo >>$LOG_FILE120echo "***************************************** check oracle process *****************************************">>$LOG_FILE121ps -ef | grep ora_ | grep -v grep | awk -F '-' '{print $2}' | awk '{print $2}' >/$TEMP_PATH/ora_process_info122ps -ef | grep ora_ | grep -v grep >>$LOG_FILE123 124# background process ckpt125if [ `grep ora_ckpt_ora92 $TEMP_PATH/ora_process_info` ]; then126COUNT=1127else128echo "LOG-Warnning: `date +%Y'-'%m'-'%d' '%H':'%M':'%S`,The Process ora_ckpt_ora92 was terminated!" >>$LOG_FILE129fi130 131# background process dbwr132if [ `grep ora_dbw0_ora92 $TEMP_PATH/ora_process_info` ]; then133COUNT=$((COUNT+1))134else135echo "LOG-Warnning: `date +%Y'-'%m'-'%d' '%H':'%M':'%S`,The Process ora_dbw0_ora92 was terminated !" >>$LOG_FILE136fi137 138# background process reco139if [ `grep ora_reco_ora92 $TEMP_PATH/ora_process_info` ]; then140COUNT=$((COUNT+1))141else142echo "LOG-Warnning: `date +%Y'-'%m'-'%d' '%H':'%M':'%S`,The Process ora_reco_ora92 was terminated !" >>$LOG_FILE143fi144 145# background process lgwr146if [ `grep ora_lgwr_ora92 $TEMP_PATH/ora_process_info` ]; then147COUNT=$((COUNT+1))148else149echo "LOG-Warnning: `date +%Y'-'%m'-'%d' '%H':'%M':'%S`,The Process ora_lgwr_ora92 was terminated !" >>$LOG_FILE150fi151 152# background process pmon153if [ `grep ora_pmon_ora92 $TEMP_PATH/ora_process_info` ]; then154COUNT=$((COUNT+1))155else156echo "LOG-Warnning: `date +%Y'-'%m'-'%d' '%H':'%M':'%S`,The Process ora_pmon_ora92 was terminated !" >>$LOG_FILE157fi158 159# background process smon160if [ `grep ora_smon_ora92 $TEMP_PATH/ora_process_info` ]; then161COUNT=$((COUNT+1))162else163echo "LOG-Warnning: `date +%Y'-'%m'-'%d' '%H':'%M':'%S`,The Process ora_smon_ora92 was terminated !" >>$LOG_FILE164fi165 166if [ "$COUNT" -eq 6 ];then167echo >>$LOG_FILE168echo " The main six Oracle processes is OK !!" >>$LOG_FILE169else170:171fi172 173 174#175# Check the oracle tablespace.176#177echo >>$LOG_FILE178echo >>$LOG_FILE179echo "***************************************** check oracle tablespace *****************************************">>$LOG_FILE180#su - oracle -c sqlplus dxh/dxh < /home/guest/dxhwh/niyl/tablespace_query.sql >>$LOG_FILE181sqlplus -s dxh/dxh < $TEMP_PATH/ts_info182set pagesize 100183set linesize 100184col status for a10185col tablespace_name for a20186col contents for a10187col "size(M)" for a15188col used for a15189col pct for a10190select d.status, d.tablespace_name,191TO_CHAR(NVL(a.bytes / 1024 /1024, 0),'99G999G990') "size(M)",192TO_CHAR(NVL(a.bytes - NVL(f.bytes, 0),0)/1024/1024, '99G999G990D00') used,193TO_CHAR(NVL((a.bytes - NVL(f.bytes, 0)) / a.bytes * 100, 0), '990D00')||'%' pct194FROM sys.dba_tablespaces d,195(select tablespace_name, sum(bytes) bytes from dba_data_files group by tablespace_name) a,196(select tablespace_name, sum(bytes) bytes from dba_free_space group by tablespace_name) f197WHERE d.tablespace_name = a.tablespace_name(+)198AND d.tablespace_name = f.tablespace_name(+)199order by tablespace_name ;200exit201!EOF202 203cat $TEMP_PATH/ts_info>>$LOG_FILE204cat $TEMP_PATH/ts_info |grep ONLINE |awk '{print $2":"$3":"$4":"$5}' |while read line205do206ts_name=$(echo $line |awk -F ':' '{print $1}')207ts_total=$(echo $line |awk -F ':' '{print $2}')208ts_used=$(echo $line |awk -F ':' '{print $3}')209ts_used_pct=$(echo $line |awk -F ':' '{print $4}' |awk -F '%' '{print $1}'|awk -F '.' '{print $1}')210if [ "$ts_used_pct" -gt "$TS_VALUE" -o "$ts_used_pct" -eq "$TS_VALUE" ]; then211echo "LOG-Warnning: `date +%Y'-'%m'-'%d' '%H':'%M':'%S`,資料表空間$ts_name 的剩餘空間緊張,請儘快清理資料表空間!" >>$LOG_FILE212else213echo " The tablespace of $ts_name is OK!!" >>$LOG_FILE214fi215done216 217#218# Check the oracle Job.219#220echo >>$LOG_FILE221echo >>$LOG_FILE222echo "***************************************** check oracle job *****************************************">>$LOG_FILE223sqlplus -s dxh/dxh <> $LOG_FILE224col job for 999225col last_date for a20226col next_date for a20227col what for a40228set linesize 120229 230select job,what,231to_char(last_date,'yyyy-mm-dd hh24:mi:ss') last_date,232to_char(next_date,'yyyy-mm-dd hh24:mi:ss') next_date,233failures234from dba_jobs235order by job;236!!ET237 238sqlplus -s dxh/dxh < $TEMP_PATH/job_info239col flag for a5240col rou for 99999241select 'XXX' flag,job,failures,broken,round(next_date-sysdate,2)*100 rou from dba_jobs order by job;242!EOF243 244cat $TEMP_PATH/job_info |grep XXX |awk '{print $2,$3,$4,$5}' |while read line245do246jobnum=`echo $line | awk '{print $1}'`247failure=`echo $line | awk '{print $2}'`248broken=`echo $line | awk '{print $3}'`249round=`echo $line | awk '{print $4}'`250if [ "$jobnum" -eq 3 -o "$jobnum" -eq 4 ] ; then251 252if [ "$failure" -eq 0 -a "$broken"="N" -a "$round" -le 100 ]; then253echo " The Job $jobnum is OK!!" >>$LOG_FILE254else255echo "LOG-Warnning: `date +%Y'-'%m'-'%d' '%H':'%M':'%S`,The Job $jobnum was terminated !" >>$LOG_FILE256fi257else258if [ "$failure" -eq 0 -a "$broken"="N" -a "$round" -eq 0 ]; then259echo " The Job $jobnum is OK!!" >>$LOG_FILE260else261echo "LOG-Warnning: `date +%Y'-'%m'-'%d' '%H':'%M':'%S`,The Job $jobnum was terminated !" >>$LOG_FILE262fi263fi264done265 266#267# Check the oracle session.268#269sqlplus -s dxh/dxh <> $LOG_FILE270select 'The Total sessions number is '||count(*)||'.' from v$session ;271select 'table mt: ' ,count(*) from t_dxh_mt where msgresult='SUCCESS';272select 'table detect:' ,count(*) from t_dxh_opendetect where msgresult='SUCCESS';273exit274!275 276 277#278# Check oracle table for user information sync.279#280echo >>$LOG_FILE281echo >>$LOG_FILE282echo "*****************************************oracle 同步資料檢查資訊輸出*****************************************">>$LOG_FILE283sqlplus -s ccmdxh/ccm@ccmdxh < $TEMP_PATH/jiya_info284select 'NUM_P630' flag,count(*) from T_DXH_USERINFO ;285select 'NUM_p570' flag,count(*) from T_DXH_USERINFO2 ;286!287cat $TEMP_PATH/jiya_info >>$LOG_FILE288cat $TEMP_PATH/jiya_info |grep NUM_| grep -v COUNT | while read line289do290zhuji=`echo $line |awk '{print $1}'`291user_num=`echo $line |awk '{print $2}'`292if [ "$user_num" -le 2000 ]; then293echo " The node $zhuji users sync is OK!! " >>$LOG_FILE294else295echo "LOG-Warnning: The node $zhuji users sync terminated abnormally.Please check !!" >>$LOG_FILE296fi297done298 299#300# Check oracle alert log.301#302echo >>$LOG_FILE303echo >>$LOG_FILE304echo "***************************************** check oracle alert log *****************************************">>$LOG_FILE305tail -300 $ORACLE_BASE/admin/ora92/bdump/alert_ora92.log | grep -v Thread |306grep -v Current | grep -v "`date +'%a %h'`" | grep -v ":[0-9][0-9]:" >>$LOG_FILE307 308#309# Check system error report.310#311echo >>$LOG_FILE312echo >>$LOG_FILE313echo "***************************************** check system err *****************************************">>$LOG_FILE314errpt | head -10 >>$LOG_FILE315day=`date +%D |awk -F "/" '{print $1$2}'`316errpt | awk '{print $2}' | grep ^$day317if [ $? -eq 0 ] ; then318echo "LOG-Warnning: `date +%Y'-'%m'-'%d' '%H':'%M':'%S`,The system has found a error today.Please check the error report." >>$LOG_FILE319else320echo >>$LOG_FILE321echo " There is no system error report today.System is OK!!" >>$LOG_FILE322fi323 324#325# Check HACMP.326#327echo >>$LOG_FILE328echo >>$LOG_FILE329echo "***************************************** check HACMP status *****************************************">>$LOG_FILE330/usr/es/sbin/cluster/clstat -o > $TEMP_PATH/ha_info331lssrc -g cluster >> $TEMP_PATH/ha_info332cat $TEMP_PATH/ha_info >>$LOG_FILE333echo >>$LOG_FILE334cat $TEMP_PATH/ha_info| grep "Node:" |awk -F ':' '{print $2,$3}' | awk '{print $1,$3}' | while read line335do336node=$(echo $line | awk '{print $1}')"'s"337echo $line |grep UP$ >/dev/null338if [ "$?" -eq 0 ]; then339echo " The node $node is OK!!" >>$LOG_FILE340else341echo "`date +%Y'-'%m'-'%d' '%H':'%M':'%S`,LOG-Warnning: The node $node status is DOWN ,it was terminated ." >>$LOG_FILE342fi343done 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.