• ADG监控


    cx_Oracle环境配置

    export ORACLE_BASE=/u01/app/oracle
    export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib/
    export TNS_ADMIN=$ORACLE_HOME/network/admin/

    脚本正本

    #!/usr/bin/python
    # coding:utf-8
    
    __author__ = 'Jipu FANG'
    
    import cx_Oracle
    import sys
    
    # 主库状态
    def pdb():
        conn = cx_Oracle.connect('user/passwd@rac01/orcl')  
        cursor = conn.cursor ()
        cursor.execute ("select switchover_status from v$database")
        row = cursor.fetchone ()
        status = row[0]
        if status == 'TO STANDBY' or status == 'SESSIONS ACTIVE':
            cursor.close ()
    	conn.close ()
            return "0"
        else:
    	return "200"
    
    # 备库状态
    def sdb():
        conn = cx_Oracle.connect('user/passwd@rdata01/phydb')  
        cursor = conn.cursor ()
        cursor.execute ("select switchover_status from v$database")
        row = cursor.fetchone ()
        status = row[0]
        if status == 'NOT ALLOWED':
            cursor.close ()
        	conn.close ()
            return "0"
        else:
    	return "200"
    
    # DG延迟,基于SCN
    class dg_delay():
        def rac1_scn(self):
        	conn = cx_Oracle.connect('user/passwd@rac01/orcl')
        	cursor = conn.cursor ()
        	cursor.execute ("select current_scn from v$database")
        	row = cursor.fetchone ()
    	if row:
                scn = row[0]
    	else:
    	    scn = 0
        	cursor.close()
        	conn.close ()
    	return scn 
     
        def sdb_scn(self):
            conn = cx_Oracle.connect('user/passwd@rdata01/phydb')
            cursor = conn.cursor ()
            cursor.execute ("select current_scn from v$database")
            row = cursor.fetchone ()
    	if row:
                scn = row[0]
    	else:
    	    scn = 0
            cursor.close()
            conn.close ()
            return scn
    
        def run(self):
    	scn = int(self.rac1_scn()) - int(self.sdb_scn())
    	return scn
    		
    item = sys.argv[1]
    
    if __name__ == '__main__':
    	if item == 'pdb':
    	    print pdb()
     	elif item == 'sdb':
    	    print sdb()
    	elif item == 'dg':
    	    a = dg_delay()
    	    print a.run()
    
    

    脚本执行

    # ./check_dg_delay_status.py dg
    5
    
  • 相关阅读:
    Codeforces 813F Bipartite Checking 线段树 + 并查集
    Codeforces 263E Rhombus (看题解)
    Codeforces 173E Camping Groups hash
    Codeforces 311C Fetch the Treasure 取模意义下的最短路 (看题解)
    R 培训之 Table
    Docker命令详解
    Celery的实践指南
    Using Celery with Djang
    PostgreSQL
    改时区参考
  • 原文地址:https://www.cnblogs.com/GXLo/p/7562337.html
Copyright © 2020-2023  润新知