歡迎您光臨本站 註冊首頁

nagios監控oracle遇到的問題

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

nagios監控oracle遇到的問題

這是報錯的內容:
/usr/local/nagios/libexec/>/usr/local/nagios/libexec/check_oracle --tablespace ccpbs system manager ccpbs  90 80
/usr/local/nagios/libexec/check_oracle: line 270: [: : integer expression expected
/usr/local/nagios/libexec/check_oracle: line 274: [: : integer expression expected
/usr/local/nagios/libexec/check_oracle: line 278: [: : integer expression expected
ccpbs : ccpbs OK - % used [  /  MB available ]|ccpbs=%;80;90;0;100

這是check_oracle腳本的內容:

/usr/local/nagios/libexec/>cat check_oracle
#! /bin/sh
#
# latigid010@yahoo.com
# 01/06/2000
#
#  This Nagios plugin was created to check Oracle status
#
PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
ORACLE_HOME=/opt/oracle/ora9.2.0.4
PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION="1.4.14"

. $PROGPATH/utils.sh


print_usage() {
  echo "Usage:"
  echo "  $PROGNAME --tns "
  echo "  $PROGNAME --db "
  echo "  $PROGNAME --login "
  echo "  $PROGNAME --cache "
  echo "  $PROGNAME --tablespace "
  echo "  $PROGNAME --oranames "
  echo "  $PROGNAME --help"
  echo "  $PROGNAME --version"
}

print_help() {
  print_revision $PROGNAME $REVISION
  echo ""
  print_usage
  echo ""
  echo "Check Oracle status"
  echo ""
  echo "--tns SID/IP Address"
  echo "   Check remote TNS server"
  echo "--db SID"
  echo "   Check local database (search /bin/ps for PMON process) and check"
  echo "   filesystem for sgadefORACLE_SID.dbf"
  echo "--login SID"
  echo "   Attempt a dummy login and alert if not ORA-01017: invalid username/password"
  echo "--cache"
  echo "   Check local database for library and buffer cache hit ratios"
  echo "       --->  Requires Oracle user/password and SID specified."
  echo "                --->  Requires select on v_$sysstat and v_$librarycache"
  echo "--tablespace"
  echo "   Check local database for tablespace capacity in ORACLE_SID"
  echo "       --->  Requires Oracle user/password specified."
  echo "                --->  Requires select on dba_data_files and dba_free_space"
  echo "--oranames Hostname"
  echo "   Check remote Oracle Names server"
  echo "--help"
  echo "   Print this help screen"
  echo "--version"
  echo "   Print version and license information"
  echo ""
  echo "If the plugin doesn't work, check that the ORACLE_HOME environment"
  echo "variable is set, that ORACLE_HOME/bin is in your PATH, and the"
  echo "tnsnames.ora file is locatable and is properly configured."
  echo ""
  echo "When checking local database status your ORACLE_SID is case sensitive."
  echo ""
  echo "If you want to use a default Oracle home, add in your oratab file:"
  echo "*:/opt/app/oracle/product/7.3.4:N"
  echo ""
  support
}

case "$1" in
1)
    cmd='--tns'
    ;;
2)
    cmd='--db'
    ;;
*)
    cmd="$1"
    ;;
esac

# Information options
case "$cmd" in
--help)
                print_help
    exit $STATE_OK
    ;;
-h)
                print_help
    exit $STATE_OK
    ;;
--version)
                print_revision $PROGNAME $REVISION
    exit $STATE_OK
    ;;
-V)
                print_revision $PROGNAME $REVISION
    exit $STATE_OK
    ;;
esac

# Hunt down a reasonable ORACLE_HOME
if [ -z "$ORACLE_HOME" ] ; then
        # Adjust to taste
        for oratab in /var/opt/oracle/oratab /etc/oratab
        do
        [ ! -f $oratab ] && continue
        ORACLE_HOME=`IFS=:
                while read SID ORACLE_HOME junk;
                do
                        if [ "$SID" = "$2" -o "$SID" = "*" ] ; then
                                echo $ORACLE_HOME;
                                exit;
                        fi;
                done < $oratab`
        [ -n "$ORACLE_HOME" ] && break
        done
fi
# Last resort
[ -z "$ORACLE_HOME" -a -d $PROGPATH/oracle ] && ORACLE_HOME=$PROGPATH/oracle

if [ "$cmd" != "--db" ]; then
        if [ -z "$ORACLE_HOME" -o ! -d "$ORACLE_HOME" ] ; then
                echo "Cannot determine ORACLE_HOME for sid $2"
                exit $STATE_UNKNOWN
        fi
fi
PATH=$PATH:$ORACLE_HOME/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export ORACLE_HOME PATH LD_LIBRARY_PATH

case "$cmd" in
--tns)
    tnschk=` tnsping $2`
    tnschk2=` echo  $tnschk | grep -c OK`
    if [ ${tnschk2} -eq 1 ] ; then
        tnschk3=` echo $tnschk | sed -e 's/.*(//' -e 's/).*//'`
        echo "OK - reply time ${tnschk3} from $2"
        exit $STATE_OK
    else
        echo "No TNS Listener on $2"
        exit $STATE_CRITICAL
    fi
    ;;
--oranames)
    namesctl status $2 | awk '
    /Server has been running for:/ {
        msg = "OK: Up"
        for (i = 6; i <= NF; i++) {
            msg = msg " " $i
        }
        status = '$STATE_OK'
    }
    /error/ {
        msg = "CRITICAL: " $0
        status = '$STATE_CRITICAL'
    }
    END {
        print msg
        exit status
    }'
    ;;
--db)
    pmonchk=`ps -ef | grep -v grep | grep -c "ora_pmon_${2}$"`
    if [ ${pmonchk} -ge 1 ] ; then
        echo "${2} OK - ${pmonchk} PMON process(es) running"
        exit $STATE_OK
    #if [ -f $ORACLE_HOME/dbs/sga*${2}* ] ; then
        #if [ ${pmonchk} -eq 1 ] ; then
    #utime=`ls -la $ORACLE_HOME/dbs/sga*$2* | cut -c 43-55`
            #echo "${2} OK - running since ${utime}"
            #exit $STATE_OK
        #fi
    else
        echo "${2} Database is DOWN"
        exit $STATE_CRITICAL
    fi
    ;;
--login)
    loginchk=`sqlplus dummy/user@$2 < /dev/null`
    loginchk2=` echo  $loginchk | grep -c ORA-01017`
    if [ ${loginchk2} -eq 1 ] ; then
        echo "OK - dummy login connected"
        exit $STATE_OK
    else
        loginchk3=` echo "$loginchk" | grep "ORA-" | head -1`
        echo "CRITICAL - $loginchk3"
        exit $STATE_CRITICAL
    fi
    ;;
--cache)
    if [ ${5} -gt ${6} ] ; then
        echo "UNKNOWN - Warning level is less then Crit"
        exit $STATE_UNKNOWN
    fi
    result=`sqlplus -s ${3}/${4}@${2} << EOF
set pagesize 0
set numf '9999999.99'
select (1-(pr.value/(dbg.value+cg.value)))*100
from v\\$sysstat pr, v\\$sysstat dbg, v\\$sysstat cg
where pr.name='physical reads'
and dbg.name='db block gets'
and cg.name='consistent gets';
EOF`

    if [ -n "`echo $result | grep ORA-`" ] ; then
      error=` echo "$result" | grep "ORA-" | head -1`
      echo "CRITICAL - $error"
      exit $STATE_CRITICAL
    fi

    buf_hr=`echo "$result" | awk '/^+$/ {print int($1)}'`
    buf_hrx=`echo "$result" | awk '/^+$/ {print $1}'`
    result=`sqlplus -s ${3}/${4}@${2} << EOF
set pagesize 0
set numf '9999999.99'
select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100
from v\\$librarycache lc;
EOF`

    if [ -n "`echo $result | grep ORA-`" ] ; then
      error=` echo "$result" | grep "ORA-" | head -1`
      echo "CRITICAL - $error"
      exit $STATE_CRITICAL
    fi

    lib_hr=`echo "$result" | awk '/^+$/ {print int($1)}'`
    lib_hrx=`echo "$result" | awk '/^+$/ {print $1}'`

    if [ $buf_hr -le ${5} -o $lib_hr -le ${5} ] ; then
        echo "${2} CRITICAL - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100"
        exit $STATE_CRITICAL
    fi
    if [ $buf_hr -le ${6} -o $lib_hr -le ${6} ] ; then
        echo "${2} WARNING  - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100"
        exit $STATE_WARNING
    fi
    echo "${2} OK - Cache Hit Rates: $lib_hrx% Lib -- $buf_hrx% Buff|lib=$lib_hrx%;${6};${5};0;100 buffer=$buf_hrx%;${6};${5};0;100"

    exit $STATE_OK
    ;;
--tablespace)
    if [ ${6} -lt ${7} ] ; then
        echo "UNKNOWN - Warning level is more then Crit"
        exit $STATE_UNKNOWN
    fi
    result=`sqlplus -s ${3}/${4}@${2} << EOF
set pagesize 0
set numf '9999999.99'
select NVL(b.free,0.0),a.total,100 - trunc(NVL(b.free,0.0)/a.total * 1000) / 10 prc
from (
select tablespace_name,sum(bytes)/1024/1024 total
from dba_data_files group by tablespace_name) A
LEFT OUTER JOIN
( select tablespace_name,sum(bytes)/1024/1024 free
from dba_free_space group by tablespace_name) B
ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}';
EOF`

    if [ -n "`echo $result | grep ORA-`" ] ; then
      error=` echo "$result" | grep "ORA-" | head -1`
      echo "CRITICAL - $error"
      exit $STATE_CRITICAL
    fi

    ts_free=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}'`
    ts_total=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}'`
    ts_pct=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}'`
    ts_pctx=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}'`
   第270行  if [ "$ts_free" -eq 0 -a "$ts_total" -eq 0 -a "$ts_pct" -eq 0 ] ; then
        echo "No data returned by Oracle - tablespace $5 not found?"
        exit $STATE_UNKNOWN
    fi
    第274行 if [ "$ts_pct" -ge ${6} ] ; then
        echo "${2} : ${5} CRITICAL - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100"
        exit $STATE_CRITICAL
    fi
第278行    if [ "$ts_pct" -ge ${7} ] ; then
        echo "${2} : ${5} WARNING  - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100"
        exit $STATE_WARNING
    fi    echo "${2} : ${5} OK - $ts_pctx% used [ $ts_free / $ts_total MB available ]|${5}=$ts_pctx%;${7};${6};0;100"
    exit $STATE_OK
    ;;
*)
    print_usage
                exit $STATE_UNKNOWN
esac
《解決方案》

仔細看了下, 第270行等的腳本都沒有改動過,應該不是這裡的問題!
《解決方案》

代碼這麼長,看的眼睛都花了:em17:
http://www.bc889.com
http://www.clonefans.com
http://www.12bets.org
http://www.l88bet.com
http://www.baobao8.net.cn
http://www.888-888-888.org
《解決方案》

sh -x /usr/local/nagios/libexec/check_oracle --tablespace ccpbs system manager ccpbs  90 80
看看錯誤部分的變數結果及輸出。
《解決方案》

謝謝!終於有一個人肯出手幫忙了!


++ basename /usr/local/nagios/libexec/check_oracle
+ PROGNAME=check_oracle
++ echo /usr/local/nagios/libexec/check_oracle
++ sed -e 's,[\/][^\/][^\/]*$,,'
+ PROGPATH=/usr/local/nagios/libexec
+ REVISION=1.4.14
+ . /usr/local/nagios/libexec/utils.sh
++ STATE_OK=0
++ STATE_WARNING=1
++ STATE_CRITICAL=2
++ STATE_UNKNOWN=3
++ STATE_DEPENDENT=4
++ test -x /usr/bin/printf
++ ECHO=/usr/bin/printf
+ case "$1" in
+ cmd=--tablespace
+ case "$cmd" in
+ '[' -z '' ']'
+ for oratab in /var/opt/oracle/oratab /etc/oratab
+ '[' '!' -f /var/opt/oracle/oratab ']'
+ continue
+ for oratab in /var/opt/oracle/oratab /etc/oratab
+ '[' '!' -f /etc/oratab ']'
++ IFS=:
++ read SID ORACLE_HOME junk
++ '[' '#' = ccpbs -o '#' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '' = ccpbs -o '' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '# This file is used by ORACLE utilities.  It is created by root.sh' = ccpbs -o '# This file is used by ORACLE utilities.  It is created by root.sh' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '# and updated by the Database Configuration Assistant when creating' = ccpbs -o '# and updated by the Database Configuration Assistant when creating' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '# a database.' = ccpbs -o '# a database.' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '' = ccpbs -o '' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '# A colon, '\''' = ccpbs -o '# A colon, '\''' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '# the entry.  Lines beginning with a pound sign, '\''#'\'', are comments.' = ccpbs -o '# the entry.  Lines beginning with a pound sign, '\''#'\'', are comments.' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '#' = ccpbs -o '#' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '# Entries are of the form' = ccpbs -o '# Entries are of the form' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '#   $ORACLE_SID' = ccpbs -o '#   $ORACLE_SID' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '#' = ccpbs -o '#' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '# The first and second fields are the system identifier and home' = ccpbs -o '# The first and second fields are the system identifier and home' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '# directory of the database respectively.  The third filed indicates' = ccpbs -o '# directory of the database respectively.  The third filed indicates' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '# to the dbstart utility that the database should , "Y", or should not,' = ccpbs -o '# to the dbstart utility that the database should , "Y", or should not,' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '# "N", be brought up at system boot time.' = ccpbs -o '# "N", be brought up at system boot time.' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '#' = ccpbs -o '#' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '# Multiple entries with the same $ORACLE_SID are not allowed.' = ccpbs -o '# Multiple entries with the same $ORACLE_SID are not allowed.' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '#' = ccpbs -o '#' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '#' = ccpbs -o '#' = '*' ']'
++ read SID ORACLE_HOME junk
++ '[' '*' = ccpbs -o '*' = '*' ']'
++ echo /opt/oracle/ora9.2.0.4
++ exit
+ ORACLE_HOME=/opt/oracle/ora9.2.0.4
+ '[' -n /opt/oracle/ora9.2.0.4 ']'
+ break
+ '[' -z /opt/oracle/ora9.2.0.4 -a -d /usr/local/nagios/libexec/oracle ']'
+ '[' --tablespace '!=' --db ']'
+ '[' -z /opt/oracle/ora9.2.0.4 -o '!' -d /opt/oracle/ora9.2.0.4 ']'
+ PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/opt/oracle/ora9.2.0.4/bin
+ LD_LIBRARY_PATH=:/opt/oracle/ora9.2.0.4/lib
+ export ORACLE_HOME PATH LD_LIBRARY_PATH
+ case "$cmd" in
+ '[' 90 -lt 80 ']'
++ sqlplus -s system/manager@ccpbs
+ result='
no rows selected'
++ echo no rows selected
++ grep ORA-
+ '[' -n '' ']'
++ echo '
no rows selected'
++ awk '/^[ 0-9\.\t ]+$/ {print int($1)}'
+ ts_free=
++ awk '/^[ 0-9\.\t ]+$/ {print int($2)}'
++ echo '
no rows selected'
+ ts_total=
++ echo '
no rows selected'
++ awk '/^[ 0-9\.\t ]+$/ {print int($3)}'
+ ts_pct=
++ echo '
no rows selected'
++ awk '/^[ 0-9\.\t ]+$/ {print $3}'
+ ts_pctx=
+ '[' '' -eq 0 -a '' -eq 0 -a '' -eq 0 ']'
/usr/local/nagios/libexec/check_oracle: line 271: [: : integer expression expected
+ '[' '' -ge 90 ']'
/usr/local/nagios/libexec/check_oracle: line 275: [: : integer expression expected
+ '[' '' -ge 80 ']'
/usr/local/nagios/libexec/check_oracle: line 279: [: : integer expression expected
+ echo 'ccpbs : ccpbs OK - % used [  /  MB available ]|ccpbs=%;80;90;0;100'
ccpbs : ccpbs OK - % used [  /  MB available ]|ccpbs=%;80;90;0;100
+ exit 0
/root/>
《解決方案》

+ result='
no rows selected'

sqlplus沒有結果輸出,導致腳本解析出錯。
你指定的tablespace存在么?》
《解決方案》

表空間倒是有的,哦,現在不能登錄那台機了!大小寫有問題嗎?
《解決方案》

我也遇到同樣的問題,,nagios 監控oracle 插件,check_oracle   監控其他都沒問題,監控表空間就有上面同樣的問題。。不知道是腳本問題還是許可權問題,我的腳本是nagios自帶的。不知道樓主的問題解決了沒。。分享經驗哦。:em03:
《解決方案》

問題解決,看效果

本帖最後由 lq2003 於 2010-04-19 15:00 編輯

在本地執行結果如下:

root@WYdb1 # sh -x /usr/local/nagios/libexec/check_oracle --tablespace noap gdnoap ****** NOAP_PCOUNT_INDX 90 80
+ basename /usr/local/nagios/libexec/check_oracle
PROGNAME=check_oracle
+ sed -e s,[\/][^\/][^\/]*$,,
+ echo /usr/local/nagios/libexec/check_oracle
PROGPATH=/usr/local/nagios/libexec
+ sed -e s/[^0-9.]//g
+ echo $Revision: 1749 $
REVISION=1749
+ . /usr/local/nagios/libexec/utils.sh
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
+ test -x /usr/bin/printf
ECHO=/usr/bin/printf
cmd=--tablespace
+ [ -z  ]
+ [ ! -f /var/opt/oracle/oratab ]
IFS=:
+ read SID ORACLE_HOME junk
+ [ # = noap -o # = * ]
+ read SID ORACLE_HOME junk
+ [  = noap -o  = * ]
+ read SID ORACLE_HOME junk
+ [  = noap -o  = * ]
+ read SID ORACLE_HOME junk
+ [  = noap -o  = * ]
+ read SID ORACLE_HOME junk
+ [ # This file is used by ORACLE utilities.  It is created by root.sh = noap -o # This file is used by ORACLE utilities.  It is created by root.sh = * ]
+ read SID ORACLE_HOME junk
+ [ # and updated by the Database Configuration Assistant when creating = noap -o # and updated by the Database Configuration Assistant when creating = * ]
+ read SID ORACLE_HOME junk
+ [ # a database. = noap -o # a database. = * ]
+ read SID ORACLE_HOME junk
+ [  = noap -o  = * ]
+ read SID ORACLE_HOME junk
+ [ # A colon, ' = noap -o # A colon, ' = * ]
+ read SID ORACLE_HOME junk
+ [ # the entry.  Lines beginning with a pound sign, '#', are comments. = noap -o # the entry.  Lines beginning with a pound sign, '#', are comments. = * ]
+ read SID ORACLE_HOME junk
+ [ # = noap -o # = * ]
+ read SID ORACLE_HOME junk
+ [ # Entries are of the form = noap -o # Entries are of the form = * ]
+ read SID ORACLE_HOME junk
+ [ #   $ORACLE_SID = noap -o #   $ORACLE_SID = * ]
+ read SID ORACLE_HOME junk
+ [ # = noap -o # = * ]
+ read SID ORACLE_HOME junk
+ [ # The first and second fields are the system identifier and home = noap -o # The first and second fields are the system identifier and home = * ]
+ read SID ORACLE_HOME junk
+ [ # directory of the database respectively.  The third filed indicates = noap -o # directory of the database respectively.  The third filed indicates = * ]
+ read SID ORACLE_HOME junk
+ [ # to the dbstart utility that the database should , "Y", or should not, = noap -o # to the dbstart utility that the database should , "Y", or should not, = * ]
+ read SID ORACLE_HOME junk
+ [ # "N", be brought up at system boot time. = noap -o # "N", be brought up at system boot time. = * ]
+ read SID ORACLE_HOME junk
+ [ # = noap -o # = * ]
+ read SID ORACLE_HOME junk
+ [ # Multiple entries with the same $ORACLE_SID are not allowed. = noap -o # Multiple entries with the same $ORACLE_SID are not allowed. = * ]
+ read SID ORACLE_HOME junk
+ [ # = noap -o # = * ]
+ read SID ORACLE_HOME junk
+ [ # = noap -o # = * ]
+ read SID ORACLE_HOME junk
+ [ noap = noap -o noap = * ]
+ echo /export/home/oracle/product/10.2
+ exit
ORACLE_HOME=/export/home/oracle/product/10.2
+ [ -n /export/home/oracle/product/10.2 ]
+ break
+ [ -z /export/home/oracle/product/10.2 -a -d /usr/local/nagios/libexec/oracle ]
+ [ --tablespace != --db ]
+ [ -z /export/home/oracle/product/10.2 -o ! -d /export/home/oracle/product/10.2 ]
PATH=/usr/local/bin:/usr/sbin:/usr/sfw/bin:/usr/sfw/sbin:/usr/ccs/bin:/usr/sadm/admin/bin:/usr/local/ssl/bin:/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/openwin/bin:/usr/dt/bin:/usr/platform/SUNW,SPARC-Enterprise/sbin:/opt/sun/bin:/usr/cluster/bin:/usr/cluster/lib/sc:/opt/SUNWexplo/bin:/opt/SUNWsneep/bin:/opt/CTEact/bin:/export/home/oracle/product/10.2/bin
LD_LIBRARY_PATH=/usr/local/lib:/usr/local/ssl/lib:/usr/sfw/lib/::/usr/openwin/lib:/export/home/oracle/product/10.2/lib
+ export ORACLE_HOME PATH LD_LIBRARY_PATH
+ [ 90 -lt 80 ]
+ sqlplus -s gdnoap/*****@noap
set pagesize 0
set numf '9999999.99'
select NVL(b.free,0.0),a.total,100 - trunc(NVL(b.free,0.0)/a.total * 1000) / 10 prc
from (
select tablespace_name,sum(bytes)/1024/1024 total
from dba_data_files group by tablespace_name) A
LEFT OUTER JOIN
( select tablespace_name,sum(bytes)/1024/1024 free
from dba_free_space group by tablespace_name) B
ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='NOAP_PCOUNT_INDX';
result=      112642.63   122800.00         8.30
+ grep ORA-
+ echo 112642.63 122800.00 8.30
+ [ -n  ]
+ awk /^[ 0-9\.\t ]+$/ {print int($1)}
+ echo       112642.63   122800.00         8.30
ts_free=112642
+ awk /^[ 0-9\.\t ]+$/ {print int($2)}
+ echo       112642.63   122800.00         8.30
ts_total=122800
+ awk /^[ 0-9\.\t ]+$/ {print int($3)}
+ echo       112642.63   122800.00         8.30
ts_pct=8
+ awk /^[ 0-9\.\t ]+$/ {print $3}
+ echo       112642.63   122800.00         8.30
ts_pctx=8.30
+ [ 112642 -eq 0 -a 122800 -eq 0 -a 8 -eq 0 ]
+ [ 8 -ge 90 ]
+ [ 8 -ge 80 ]
+ echo noap : NOAP_PCOUNT_INDX OK - 8.30% used [ 112642 / 122800 MB available ]|NOAP_PCOUNT_INDX=8.30%;80;90;0;100
noap : NOAP_PCOUNT_INDX OK - 8.30% used [ 112642 / 122800 MB available ]|NOAP_PCOUNT_INDX=8.30%;80;90;0;100
《解決方案》

本帖最後由 lq2003 於 2010-04-19 15:01 編輯

本地執行:
$ /usr/local/nagios/libexec/check_oracle --tablespace noap gdnoap ****** NOAP_PCOUNT_DATA 90 80
noap : NOAP_PCOUNT_DATA WARNING  - 81.40% used [ 158696 / 851567 MB available ]|NOAP_PCOUNT_DATA=81.40%;80;90;0;100
伺服器端執行:
# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.22 -c check_oracle_tablespace
noap : NOAP_PCOUNT_DATA OK - % used [  /  MB available ]|NOAP_PCOUNT_DATA=%;80;90;0;100

服務端執行的結果,依然是不完全。
root@WYdb1 # id  -a nagios
uid=101(nagios) gid=102(nagios) groups=100(dba),101(oinstall)

[火星人 ] nagios監控oracle遇到的問題已經有1141次圍觀

http://coctec.com/docs/service/show-post-641.html