zoukankan      html  css  js  c++  java
  • 转 nagios监控oracle运行状况

    https://blog.csdn.net/heizistudio/article/details/8638488

    nrpe安装脚本 

    nagios-plugins-1.4.13.tar.gz
    nrpe-2.8.tar.gz
    源码包文件提前下载好

    [root@dd]more install.sh 
    #!/bin/bash
    tar -xvzf nagios-plugins-1.4.13.tar.gz
    cd nagios-plugins-1.4.13
    ./configure
    make
    make install
    groupadd nagios
    useradd -g nagios -s /sbin/nologin nagios
    echo !@NA#$gI%o^S | passwd nagios --stdin
    cd ..
    tar -xvzf nrpe-2.8.tar.gz
    cd nrpe-2.8
    ./configure
    make all
    make install-plugin
    make install-daemon
    make install-daemon-config
    echo "OK!"
    [root@dd]

    修改  nrpe文件

    vim /usr/local/nagios/etc/nrpe.cfg

    #nrpe_user=nagios
    nrpe_user=oracle ---以oracle用户运行

    allowed_hosts=127.0.0.1,192.169.169.60  --添加监控允许IP

    修改check_oracle插件脚本

    vim /usr/local/nagios/libexec/check_oracle

    添加两行

    #! /bin/sh
    #
    latigid010@yahoo.com
    # 01/06/2000
    #
    #  This Nagios plugin was created to check Oracle status
    #
    ORACLE_HOME=/opt/oracle/product/10g
    PATH=$ORACLE_HOME/bin:$PATH

    vim +257 /usr/local/nagios/libexec/check_oracle

    257 ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name=upper('${5}');---方便监控

    修改 /usr/local/nagios/etc/nrpe.cfg 文件

    。加入以下内容:

    #Check Oracle

    command[check_oracle_tns]=/usr/local/nagios/libexec/check_oracle –tns orcl

    command[check_oracle_db]=/usr/local/nagios/libexec/check_oracle –db orcl

    command[check_oracle_login]=/usr/local/nagios/libexec/check_oracle –login orcl c

    ommand[check_oracle_cache]=/usr/local/nagios/libexec/check_oracle –cache orcl system lkjsdf 80 90

    command[check_oracle_tablespace]=/usr/local/nagios/libexec/check_oracle –tablespace orcl system lkjsdf tab 90 80

    具体参数写法请参考 check_oracle –help

    二、 配置 nrpe 服务
    修改 /usr/local/nagios/etc/nrpe.cfg 文件。加入以下内容:
    #Check Oracle
    command[check_oracle_tns]=/usr/local/nagios/libexec/check_oracle –tns orcl
    command[check_oracle_db]=/usr/local/nagios/libexec/check_oracle –db orcl
    command[check_oracle_login]=/usr/local/nagios/libexec/check_oracle –login orcl
    command[check_oracle_cache]=/usr/local/nagios/libexec/check_oracle –cache orcl system lkjsdf 80 90
    command[check_oracle_tablespace]=/usr/local/nagios/libexec/check_oracle –tablespace orcl system lkjsdf tab 90 80
    具体参数写法请参考 check_oracle –help。
    配置完成后,重启 xinetd 服务。
    三、配置 Nagios 服务端
    1.安装 nrpe 脚本支持。—参考官方文档。
    2.添加 nrpe 命令配置。修改 nagios/etc/objects/command.cfg 文件:
    define command {
    command_name check_nrpe
    command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
    }
    3.在 nagios/etc/objects 添加oracle 主机配置文件。oracle.cfg 。
    define host {
    use linux-server
    host_name oracle
    alias Oracle 10g
    address 192.168.100.63
    }
    define service {
    use generic-service
    host_name oracle
    service_description TNS Check
    check_command check_nrpe!check_oracle_tns
    }
    define service {
    use generic-service
    host_name oracle
    service_description DB Check
    check_command check_nrpe!check_oracle_db
    }
    define service {
    use generic-service
    host_name oracle
    service_description Login Check
    check_command check_nrpe!check_oracle_login
    }
    define service {
    use generic-service
    host_name oracle
    service_description Cache Check
    check_command check_nrpe!check_oracle_cache
    }
    define service {
    use generic-service
    host_name oracle
    service_description Tablespace Check
    check_command check_nrpe!check_oracle_tablespace
    }
    效果图:

    NRPE 以及 Nagios-Plugin 安装文件见附件包内。NRPE 官方文档也包含在附件包呢。
    备注:
    图中 Tablespace check 还没有细调,用了错误的 table 名。
    通过修改脚本还可以监视临时表空间。

     CRITICAL - ORA-28009: connection as SYS should be as SYSDBA or SYSOPER
    [root@dd]/usr/local/nagios/libexec/check_oracle --tablespace duxiu sys oracle USERS 90 80-------勿用sys用户

    ---------------------------------------------------

    监控效果如下

    个人分类: linux管理oracle
     
     
    ###参考如下文档做alert 日志监控
     
    http://www.adp-gmbh.ch/ora/admin/scripts/read_alert_log.html

    Script to read Oracle's alert log

     
    The following script creates two tables: read_alert and read_alert_disk.
    read_alert_disk is an external table and contains the content of the alert log.
    read_alert will be empty after this script has been executed. It is used by the update_alert_log script, shown further below.
    define alert_length="2000"
    
    drop table alert_log;
    
    create table alert_log (
      alert_date date,
      alert_text varchar2(&&alert_length)
    )
    storage (initial 512k next 512K pctincrease 0);
    
    create index alert_log_idx on alert_log(alert_date)
    storage (initial 512k next 512K pctincrease 0);
    
    column db    new_value _DB    noprint;
    column bdump new_value _bdump noprint;
    
    select instance_name db from v$instance;
    
    select value bdump from v$parameter 
     where name ='background_dump_dest';
    
    
    drop   directory BDUMP;
    create directory BDUMP as '&&_bdump';
    
    drop table alert_log_disk;
    
    create table alert_log_disk ( text varchar2(&&alert_length) )
    organization external (
      type oracle_loader
      default directory BDUMP
          access parameters (
              records delimited by newline nologfile nobadfile
              fields terminated by "&" ltrim
          )
      location('alert_&&_DB..log')
    )
    reject limit unlimited;
    

    update_alert_log.sql

    Now, after the two tables are created, the alert_log table can be filled with the following script. It only loads those records that are greater than the last time it loaded. And it loads the date/time on every line for convienance. It also helps when the alertlogs get rotated. You still keep the history within an Oracle table. Finally, it also strips out all the «crap» that is really not needed to see if you are looking for errors.
    update_alert_log.sql
    set serveroutput on 
    
    declare
      
      isdate         number := 0;
      start_updating number := 0;
      rows_inserted  number := 0;
      
      alert_date     date;
      max_date       date;
      
      alert_text     alert_log_disk.text%type;
    
    begin
      
      /* find a starting date */
      select max(alert_date) into max_date from alert_log;
      
      if (max_date is null) then
        max_date := to_date('01-jan-1980', 'dd-mon-yyyy');
      end if;
      
      for r in (
        select substr(text,1,180) text from alert_log_disk
         where text not like '%offlining%' 
           and text not like 'ARC_:%' 
           and text not like '%LOG_ARCHIVE_DEST_1%'
           and text not like '%Thread 1 advanced to log sequence%'
           and text not like '%Current log#%seq#%mem#%'
           and text not like '%Undo Segment%lined%'
           and text not like '%alter tablespace%back%'
           and text not like '%Log actively being archived by another process%'
           and text not like '%alter database backup controlfile to trace%'
           and text not like '%Created Undo Segment%'
           and text not like '%started with pid%'
           and text not like '%ORA-12012%'
           and text not like '%ORA-06512%'
           and text not like '%ORA-000060:%'
           and text not like '%coalesce%'
           and text not like '%Beginning log switch checkpoint up to RBA%'
           and text not like '%Completed checkpoint up to RBA%'
           and text not like '%specifies an obsolete parameter%'
           and text not like '%BEGIN BACKUP%'
           and text not like '%END BACKUP%'
      )
      loop
      
        isdate     := 0;
        alert_text := null;
      
        select count(*) into isdate 
          from dual 
         where substr(r.text, 21) in ('2003','2004','2005','2006','2007')
           and r.text not like '%cycle_run_year%';
      
        if (isdate = 1) then  
      
          select to_date(substr(r.text, 5),'Mon dd hh24:mi:ss rrrr') 
            into alert_date 
            from dual;
      
          if (alert_date > max_date) then
            start_updating := 1;
          end if;
      
        else
          alert_text := r.text;
        end if;
      
        if (alert_text is not null) and (start_updating = 1) then
         
          insert into alert_log values (alert_date, substr(alert_text, 1, 180));
          rows_inserted := rows_inserted + 1;
          commit;
      
        end if;
      
      end loop;
      
      sys.dbms_output.put_line('Inserting after date '||to_char(max_date, 'MM/DD/RR HH24:MI:SS'));
      sys.dbms_output.put_line('Rows Inserted: '||rows_inserted);
      
      commit;
    
    end;
    /
    
    Let's execute the script:
    SQL> @update_alert_log
    
    Inserting after date 01/01/80 00:00:00
    Rows Inserted: 17361
    
    PL/SQL procedure successfully completed.
    
    The alert_log table now contains the errors as recorded in the alert.log file:
    select alert_date, substr(alert_text,1, 69) 
      from alert_log;
    
    12-JUL-06 Error stack returned to user:
    12-JUL-06 ORA-02049: timeout: distributed transaction waiting for lock
    16-JUL-06 Errors in file /usr/local/opt/oracle/admin/P2BL36A/udump/p2bl36a_ora_
    18-JUL-06 ORACLE Instance P2BL36A - Can not allocate log, archival required
    18-JUL-06 Thread 1 cannot allocate new log, sequence 265396 
    18-JUL-06 All online logs needed archiving
    18-JUL-06 ORACLE Instance P2BL36A - Can not allocate log, archival required
    18-JUL-06 Thread 1 cannot allocate new log, sequence 265397
    18-JUL-06 All online logs needed archiving
    18-JUL-06 ORACLE Instance P2BL36A - Can not allocate log, archival required
    18-JUL-06 Thread 1 cannot allocate new log, sequence 265398
    18-JUL-06 All online logs needed archiving
    23-JUL-06 Errors in file /usr/local/opt/oracle/admin/P2BL36A/udump/p2bl36a_ora_
    25-JUL-06 Errors in file /usr/local/opt/oracle/admin/P2BL36A/bdump/p2bl36a_s001
    25-JUL-06 ORA-07445: exception encountered: core dump [kpnrls()+148] [SIGBUS] [
    25-JUL-06 ORA-03113: end-of-file on communication channel
    25-JUL-06 ORA-02063: preceding line from FRD01
    25-JUL-06 found dead shared server 'S001', pid = (21, 1)
    27-JUL-06 alter tablespace TBS01
    27-JUL-06 add datafile '/ora106/ORACLE/P2BL36A/dbf/tbs01P2BL36A_32.dbf' size 20
    27-JUL-06 ORA-1119 signalled during: alter tablespace TBS01
    27-JUL-06 add datafile '/ora106/ORACL...
    27-JUL-06 alter tablespace TBS01
    27-JUL-06 add datafile '/ora106/ORACLE/P2BL36A/dbf/tbs01P2BL36A_32.dbf' size 20
    27-JUL-06 Completed: alter tablespace TBS01
    27-JUL-06 add datafile '/ora106/ORACL
    28-JUL-06 ORA-01555 caused by SQL statement below (Query Duration=59968 sec, SC
    28-JUL-06 SELECT /*+ ORDERED NO_EXPAND USE_NL(A2) INDEX(A2 "FC_REQUEST_HISTORY_
    

    Thanks

    The scripts above are provided by Shawn M Ellinger.

    Links


  • 相关阅读:
    内存跟硬盘的区别
    MCU在电动滑板车硬件实物的设计技巧
    MCU微控制器在电动滑板车技术核心剖析
    ​FRAM技术简介
    FRAM作为代码存储器应用中的单芯片解决方案
    ​内存技术词汇表
    NV-SRAM与BBSRAM之间的比较
    非易失性存储器NV-SRAM的关键属性
    游戏机电池供电的SRAM解决方案
    个人学期期末总结和对王建民老师的评价
  • 原文地址:https://www.cnblogs.com/feiyun8616/p/9035935.html
Copyright © 2011-2022 走看看