監控數據庫表數據積壓腳本(nagios)ios
#!/bin/bash
STATE_OK=0
STATE_CRITICAL=2
SMS_BLOCK_COUNT=200
SMS_WAITSEND_COUNT=800
LOG_FILE='/tmp/check_sms.log'
export ORACLE_HOME='/u01/app/oracle/product/11.2.0.4/dbhome_1/'sql
rm -rf $LOG_FILE
$ORACLE_HOME/bin/sqlplus -S ***/*****@192.168.0.**:1521/**** >>/dev/null <<EOF
set echo off --是設置不把輸出的結果顯示在屏幕上
set feedback off --關閉結果反饋
spool $LOG_FILE --調用spool以後,所產生的全部終端顯示,都會寫入spool語句定義的文件中
set heading off --只顯示數據,不顯示字段名稱
alter session set nls_date_format='YYYY-MM-DD_HH24:MI:SS';
select sysdate from dual;
select 'sms1:'||count(*) from t_sms_send1;
select 'sms2:'||count(*) from t_sms_send2;
select 'sms3:'||count(*) from t_sms_send3;
select 'sms4:'||count(*) from t_sms_send4;
select 'waitsend:'||count(*) from t_sms_waitsend;
spool off
set echo on
set heading on
set feedback on
EOF數據庫
function check()
{
local SMS_COUNT=$(grep $1 $LOG_FILE | awk -F ':' '{print $2}')
if [ $SMS_COUNT -ge $3 ]; then
echo -n "ERROR- "
# echo -n $(date '+%F_%T')
echo " $2 error!"
exit $STATE_CRITICAL
fi
}bash
if [ -f $LOG_FILE ];then
check 'sms1' 'sms_sender1' $SMS_BLOCK_COUNT session
check 'sms2' 'sms_sender2' $SMS_BLOCK_COUNT oracle
check 'sms3' 'sms_sender3' $SMS_BLOCK_COUNT app
check 'sms4' 'sms_sender4' $SMS_BLOCK_COUNT orm
check 'waitsend' 'waitsend' $SMS_WAITSEND_COUNT
echo -n "OK- "
# echo -n $(date '+%F_%T')
echo " sms_senders running..."
exit $STATE_OK
fi
echo "error."
exit $STATE_CRITICAL
it