-- You can periodically use the results of DF-h to input an External Log File, and then use Oracle's "External table" to access this "External Log File". For example:-- Step 1: write a script to regularly insert disk information into the log file:[oracle@localhost ~]$ more /data/obase/tbs_info/disk_info.sh#!/bin/bash#source /home/oracle/.bash_profilecd /data/obase/tbs_info/echo "-------- Disk Used Info of Server: 10.4.1.12 --------" > /data/obase/tbs_info/disk_info.logecho "-------- DateTime: `date` -------" >> /data/obase/tbs_info/disk_info.logdf -h >> /data/obase/tbs_info/disk_info.log-- Step 2: Use crontab to regularly execute the script (for example, execute the script once at every hour ):[oracle@localhost ~]$ crontab -e59 * * * * /data/obase/tbs_info/disk_info.sh > /data/obase/tbs_info/disk_info.log-- Step 2: Create the tbs_info directory and grant the lym User read and write permissions.CREATE DIRECTORY TBS_INFO AS '/data/obase/tbs_info/';GRANT READ,WRITE ON DIRECTORY TBS_INFO TO LYM;-- Step 3: monitor disk space usage of each database server:select dbms_metadata.get_ddl('TABLE','DISK_INFO') FROMDUAL;------------------------------------------------------------------------------ 3.1 statement for creating an external table:CREATE TABLE"LYM"."DISK_INFO"( "TEXT"VARCHAR2(150))ORGANIZATION EXTERNAL( TYPE ORACLE_LOADERDEFAULT DIRECTORY "TBS_INFO"ACCESS PARAMETERS( records delimited bynewlinenobadfilenodiscardfilenologfile)LOCATION( 'disk_info.log'))REJECT LIMIT UNLIMITED-- 3.2. Create a function to monitor disk space of each Database ServerCREATE ORREPLACEFUNCTION disk_info_funcRETURN VARCHAR2AS/******************************************************************************** Function: monitors Oracle database servers (10.4.1.12, 10.4.1.13, and 10.4.1.21)** If the usage of each disk space exceeds 80% of its total space, the disk space information is obtained!** Creator: Luo youmou** Creation Time: 2011.12.14****************************************************************************/v_cnt12 NUMBER(18,0);v_cnt13 NUMBER(18,0);v_cnt21 NUMBER(18,0);v_disk_info VARCHAR2(4000);v_disk_info_all VARCHAR2(4000);BEGINSELECT count(*) AS cntINTO v_cnt12FROM disk_info@tdw12_lymWHERE ( ( text LIKE '%8_\%%'escape '\' OR text LIKE '%9_\%%' escape '\' OR text LIKE '%100\%%' escape '\' )AND text LIKE '%/dev/sdb%' )OR ( ( text like '%9_\%%' escape '\' OR text LIKE '%100\%%' escape '\' )AND text NOT LIKE '%/dev/sdb%' );SELECT count(*) AS cntINTO v_cnt13FROM disk_info@tdw13_lymWHERE ( ( text LIKE '%8_\%%' escape '\' OR text LIKE '%9_\%%' escape '\' OR text LIKE '%100\%%' escape '\' )AND text LIKE '%/dev/sdb%' )OR ( ( text like '%9_\%%' escape '\' OR text LIKE '%100\%%' escape '\' )AND text NOT LIKE '%/dev/sdb%' );SELECT count(*) AS cntINTO v_cnt21FROM disk_infoWHERE ( ( text LIKE '%8_\%%' escape '\' OR text LIKE '%9_\%%' escape '\' OR text LIKE '%100\%%' escape '\' )AND text LIKE '%/dev/sdb%' )OR ( ( text like '%9_\%%' escape '\' OR text LIKE '%100\%%' escape '\' )AND text NOT LIKE '%/dev/sdb%' );v_disk_info := '';v_disk_info_all := '';IF v_cnt12 > 0 THENFOR i12 IN ( SELECT text as disk_info FROM disk_info@tdw12_lym ORDER BY rowid ) LOOPv_disk_info := i12.disk_info;v_disk_info_all := v_disk_info_all||v_disk_info||chr(10);END LOOP;END IF;IF v_cnt13 > 0 THENFOR i13 IN ( SELECT text as disk_info FROM disk_info@tdw13_lym ORDER BY rowid ) LOOPv_disk_info := i13.disk_info;v_disk_info_all := v_disk_info_all||v_disk_info||chr(10);END LOOP;END IF;IF v_cnt21 > 0 THENFOR i21 IN ( SELECT text as disk_info FROM disk_info ORDER BY rowid ) LOOPv_disk_info := i21.disk_info;v_disk_info_all := v_disk_info_all||v_disk_info||chr(10);END LOOP;END IF;IF v_disk_info_all IS NULL THENv_disk_info_all := 'All Disk''s spaceare OK!';END IF;RETURN v_disk_info_all;END;/------------------------------------------------------------------------------ * 3.3. Create a stored procedure and call the function to obtain disk space usage information.CREATE OR REPLACE PROCEDURE get_disk_info_procAS/******************************************************************************** Function: monitors Oracle database servers (10.4.1.12, 10.4.1.13, and 10.4.1.21)** The usage of each disk space. If the occupied space exceeds 80% of the total space, an email will be reported!** Creator: Luo youmou** Creation Time: 2011.12.14****************************************************************************/v_disk_info varchar2(4000);BEGINSELECT DISK_INFO_FUNC() INTO v_disk_info FROM dual;IF v_disk_info <> 'All Disk''s spaceare OK!' THENPROCSENDEMAIL(v_disk_info,'Disk SpaceEmergency!!!','ymluo@corp.tudou.com','13691147539@139.com','10.5.101.1','25','0',NULL,NULL,NULL,'bit 7');END IF;-- dbms_output.put_line(v_disk_info);END;/------------------------------------------------------------------------------ * 3.4. Create job timed monitoring-- Job 1.1 -- run once every 15 minutesvariable job_disk_info_proc number;begin dbms_job.submit(:job_disk_info_proc,'get_disk_info_proc;',sysdate,'SYSDATE+1/96');end;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.