wcdz 发表于 2019-1-12 11:15:32

Oracle Database 监控(check_oracle_health)

$ sqlplus / as sysdba
SQL> create user nagios identified by nagios;
User created.
SQL> grant dba to nagios;
Grant succeeded.
# yum install -y libaio libaio-devel
# groupadd oinstall
# useradd -g oinstall oracle
# echo oracle | passwd --stdin oracle
# id oracle
uid=501(oracle) gid=503(oinstall) groups=503(oinstall)
# mkdir -p /u01/app/oracle
# chown -R oracle:oinstall /u01/app
# chmod -R 775 /u01/app
# su - oracle
$ vi .bash_profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/client
export PATH=$ORACLE_HOME/bin:$PATH
export DISPLAY=192.168.1.99:0
export NLS_LANG=AMERICAN_AMERICA.UTF8
export NLS_DATE_FORMAT="yyyy-mm-dd hh24:mi:ss"
stty erase ^H
$ source .bash_profile
$ unzip p13390677_112040_Linux-x86-64_4of7.zip
$ cd client
$ ./runInstaller
# /u01/app/oraInventory/orainstRoot.sh
# vi /etc/ld.so.conf
/u01/app/oracle/product/11.2.0/client/lib
# ldconfig
# yum -y install perl-ExtUtils-MakeMaker perl-Time-HiRes
# tar zxvf DBI-1.637.tar.gz
# cd DBI-1.637
# perl Makefile.PL
# make all
# make install
# export ORACLE_HOME=/u01/app/oracle/product/11.2.0/client
# tar zxvf DBD-Oracle-1.74.tar.gz
# cd DBD-Oracle-1.74
# perl Makefile.PL
# make all
# make install
# tar zxvf check_oracle_health-3.1.2.2.tar.gz
# cd check_oracle_health-3.1.2.2
# ./configure --prefix=/usr/local/icinga \
--with-nagios-user=icinga \
--with-nagios-group=icinga \
--with-mymodules-dir=/usr/local/icinga/libexec
# make all
# make install
# su - oracle
$ cd /u01/app/oracle/product/11.2.0/db_1/network/admin/
$ vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
AMBDB =
(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.202)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = ambdb)
    )
)
$ tnsping ambdb
TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 06-AUG-2018 14:00:26
Copyright (c) 1997, 2013, Oracle.All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.202)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = ambdb)))
OK (0 msec)
# cd /usr/local/icinga/libexec/
# vi check_oracle_health
$ENV{"ORACLE_HOME"} = "/u01/app/oracle/product/11.2.0/client";
# ./check_oracle_health
Please select a mode
Copyright (c) 2008 Gerhard Lausser

Check various parameters of Oracle databases
Usage:
    check_oracle_health [-v] [-t ] --connect=
      --username= --password= --mode=
      --tablespace=
    check_oracle_health [-h | --help]
    check_oracle_health [-V | --version]
Options:
    --connect
       the connect string
    --username
       the oracle user
    --password
       the oracle user's password
    --warning
       the warning range
    --critical
       the critical range
    --mode
       the mode of the plugin. select one of the following keywords:
       tnsping                        (Check the reachability of the server)
       connection-time                  (Time to connect to the server)
       password-expiration            (Check the password expiry date for users)
       connected-users                  (Number of currently connected users)
       session-usage                  (Percentage of sessions used)
       process-usage                  (Percentage of processes used)
       rman-backup-problems             (Number of rman backup errors during the last 3 days)
       sga-data-buffer-hit-ratio      (Data Buffer Cache Hit Ratio)
       sga-library-cache-gethit-ratio   (Library Cache (Get) Hit Ratio)
       sga-library-cache-pinhit-ratio   (Library Cache (Pin) Hit Ratio)
       sga-library-cache-reloads      (Library Cache Reload (and Invalidation) Rate)
       sga-dictionary-cache-hit-ratio   (Dictionary Cache Hit Ratio)
       sga-latches-hit-ratio            (Latches Hit Ratio)
       sga-shared-pool-reload-ratio   (Shared Pool Reloads vs. Pins)
       sga-shared-pool-free             (Shared Pool Free Memory)
       pga-in-memory-sort-ratio         (PGA in-memory sort ratio)
       invalid-objects                  (Number of invalid objects in database)
       stale-statistics               (Find objects with stale optimizer statistics)
       corrupted-blocks               (Number of corrupted blocks in database)
       tablespace-usage               (Used space in tablespaces)
       tablespace-free                  (Free space in tablespaces)
       container-tablespace-free      (Free space in tablespaces of container databases)
       tablespace-remaining-time      (Remaining time until a tablespace is full)
       tablespace-fragmentation         (Free space fragmentation index)
       tablespace-io-balance            (balanced io of all datafiles)
       tablespace-can-allocate-next   (Segments (of a tablespace) can allocate next extent)
       datafile-io-traffic            (io operations/per sec of a datafile)
       datafiles-existing               (Percentage of the maximum possible number of datafiles)
       datafiles-recovery               (Check if datafiles need media recovery)
       datafiles-offline                (Check if datafiles are offline)
       asm-diskgroup-usage            (Used space in diskgroups)
       asm-diskgroup-free               (Free space in diskgroups)
       soft-parse-ratio               (Percentage of soft parses)
       switch-interval                  (Time between redo log file switches)
       retry-ratio                      (Redo buffer allocation retries)
       redo-io-traffic                  (Redo log io bytes per second)
       roll-header-contention         (Rollback segment header contention)
       roll-block-contention            (Rollback segment block contention)
       roll-hit-ratio                   (Rollback segment hit ratio (gets/waits))
       roll-wraps                     (Rollback segment wraps (per sec))
       roll-extends                     (Rollback segment extends (per sec))
       roll-avgactivesize               (Rollback segment average active size)
       seg-top10-logical-reads          (user objects among top 10 logical reads)
       seg-top10-physical-reads         (user objects among top 10 physical reads)
       seg-top10-buffer-busy-waits      (user objects among top 10 buffer busy waits)
       seg-top10-row-lock-waits         (user objects among top 10 row lock waits)
       event-waits                      (processes wait events)
       event-waiting                  (time spent by processes waiting for an event)
       enqueue-contention               (percentage of enqueue requests which must wait)
       enqueue-waiting                  (percentage of time spent waiting for the enqueue)
       latch-contention               (percentage of latch get requests which must wait)
       latch-waiting                  (percentage of time a latch spends sleeping)
       sysstat                        (change of sysstat values over time)
       dataguard-lag                  (Dataguard standby lag)
       dataguard-mrp-status             (Dataguard standby MRP status)
       flash-recovery-area-usage      (Used space in flash recovery area)
       flash-recovery-area-free         (Free space in flash recovery area)
       failed-jobs                      (The jobs which did not exit successful in the lastminutes (use --lookback))
       sql                              (any sql command returning a single number)
       sql-runtime                      (the time an sql command needs to run)
       list-tablespaces               (convenience function which lists all tablespaces)
       container-list-tablespaces       (convenience function which lists all tablespaces of all container databases)
       list-datafiles                   (convenience function which lists all datafiles)
       list-asm-diskgroups            (convenience function which lists all asm diskgroups)
       list-enqueues                  (convenience function which lists all enqueues)
       list-latches                     (convenience function which lists all latches)
       list-events                      (convenience function which lists all events)
       list-background-events         (convenience function which lists all background events)
       list-sysstats                  (convenience function which lists all statistics from v$sysstat)
# ./check_oracle_health --connect=ambdb --username=nagios --password=nagios --mode=tnsping
OK - connection established to zxmdb.
# ./check_oracle_health --connect=ambdb --username=nagios --password=nagios --mode=connection-time
OK - 0.06 seconds to connect as NAGIOS | connection_time=0.0598;1;5

# cd /usr/local/icinga/etc/objects/
# vi commands.cfg
define command{
      command_name    check_oracle
      command_line    $USER1$/check_oracle_health --connect=$ARG1$ --username=nagios --password=nagios --mode=$ARG2$
      }
# vi oracle.cfg
# define a host
define host{
      use                     linux-server
      host_name               ambdb
      alias                   ambdb
      icon_image            redhat.gif
      statusmap_image         redhat.gd2
      address               192.168.1.202
      }
# define an hostgroup
define hostgroup{
      hostgroup_namesale-oracle
      alias         database
      members         ambdb
      }
# define an servicegroup
define servicegroup {
      servicegroup_nameoracle
      aliasdatabase
}

# Define a service
define service{
      hostgroup_name                  sale-oracle
      use                           generic-service
      service_description             alive
      servicegroups                   ping
      check_command                   check_ping!100.0,20%!500.0,60%
      }
define service{
      hostgroup_name                  sale-oracle
      use                           generic-service
      service_description             os cpu usage
      servicegroups                   os
      check_command                   check_nrpe!check_cpu
      }
define service{
      hostgroup_name                  sale-oracle
      use                           generic-service
      service_description             os memory usage
      servicegroups                   os
      check_command                   check_nrpe!check_memory
      }
define service{
      hostgroup_name                  sale-oracle
      use                           generic-service
      service_description             os disk usage
      servicegroups                   os
      check_command                   check_nrpe!check_disk
      }
define service{
      hostgroup_name                  sale-oracle
      use                           generic-service
      service_description             os network usage
      servicegroups                   os
      check_command                   check_nrpe!check_network
      }
define service{
      hostgroup_name                  sale-oracle
      use                           generic-service
      service_description             os uptime
      servicegroups                   os
      check_command                   check_nrpe!check_uptime
      }
define service{
      host_name                     ambdb
      use                           generic-service
      service_description             oracle tnsping
      servicegroups                   oracle
      check_command                   check_oracle!zxmdb!tnsping
      }
define service{
      host_name                     ambdb
      use                           generic-service
      service_description             oracle connection-time
      servicegroups                   oracle
      check_command                   check_oracle!zxmdb!connection-time
      }
# cd /usr/local/icinga/etc      
# vi icinga.cfg
cfg_file=/usr/local/icinga/etc/objects/oracle.cfg
# service icinga restart
Running configuration check...OK
Stopping Icinga: Waiting for icinga to exit ..Stopping icinga done.
Starting icinga: Starting icinga done.


页: [1]
查看完整版本: Oracle Database 监控(check_oracle_health)