zoukankan      html  css  js  c++  java
  • get_slave_status.py

    #!/usr/bin/env python
    #-*- encoding: utf8 -*-

    import mysql.connector
    import get_mysql_conn_info
        
    """
    SHOW SLAVE STATUS命令输出内容
    """
    class GetSlaveResult:
        """
        getdbconfig 参数是一个列表,第一列是IP,第二列是账号,第三列是密码,第四列是端口号。
        """   
        def __init__(self,getdbconfig):       
            self.getdbconfig = getdbconfig
             
        """
        获取 SHOW SLAVE STATUS 输出结果
        """
        def get_slave_status(self):
            dbconfig = self.getdbconfig
            for i in range(int(len(dbconfig))):                           
                show_slave_status = "SHOW slave STATUS;"        
                cnn = mysql.connector.connect(host=dbconfig[i][0] ,user=dbconfig[i][1] ,password=dbconfig[i][2] ,port=dbconfig[i][3])
                cursor = cnn.cursor(dictionary=True)
                cursor.execute(show_slave_status)
                result_fet = cursor.fetchall()
                result = result_fet[0]
                result["checkmysql_host"] = dbconfig[i][0]
                result["checkmysql_user"] = dbconfig[i][1]
                result["checkmysql_port"] = int(dbconfig[i][3])
                return result        
                                                         
        """
        检查SHOW SLAVE STATUS状态
        """
        def check_slave_status(self):
            check_ture_false_slave_status = True
            result = self.get_slave_status()
            if result.get('Slave_IO_Running') == 'Yes' and result.get('Slave_SQL_Running') == 'Yes':
                pass
            else:
                check_ture_false_slave_status = False
            print  "主机名: %s , 端口号: %s , Slave_IO_Running 状态 = %s , Slave_SQL_Running 状态 = %s " %(str(result.get('checkmysql_host')),str(result.get('checkmysql_port')),str(result.get('Slave_IO_Running')),str(result.get('Slave_SQL_Running')))
     
        """
        获取Last_SQL_Error内容
        """
        def get_last_sql_error(self):
            check_ture_false_last_sql_error = True
            result = self.get_slave_status()     
            if result.get('Last_SQL_Error')== '':
                pass
            else:
                check_ture_false_last_sql_error = False
            print  "主机名: %s , 端口号: %s , Last_SQL_Error 内容 = %s " %(str(result.get('checkmysql_host')),str(result.get('checkmysql_port')),str(result.get('Last_SQL_Error')))
                    
    checkdbconfig = get_mysql_conn_info.GetConn('/data/lgj/dblist.xlsx').get_csv()

    print_result = GetSlaveResult(checkdbconfig)
    print_result.check_slave_status()
    print_result.get_last_sql_error()
     


  • 相关阅读:
    不同地区Android开发者使用哪些设备测试APP?
    IIS6、IIS7.5设置网站默认首页方法(Directory Listing Denied)
    大数据正在改变我们的生活
    如何在MySQL中使用explain查询SQL的执行计划?
    整合spring cloud云架构
    对SQL 优化,提升性能!
    传统分布式架构如何进行容器化升级
    Android开发实践:Android.mk模板
    如何从代码层面优化系统性能
    德国又出超实用的厨房神器
  • 原文地址:https://www.cnblogs.com/liang545621/p/7616032.html
Copyright © 2011-2022 走看看