码迷,mamicode.com
首页 > 数据库 > 详细

python 监控mysql主从

时间:2018-10-22 15:42:45      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:pass   exception   cache   use   cut   cep   final   span   exec   

#!/usr/bin/env python
#-*- coding: utf-8 -*-
import os
os.environ[PYTHON_EGG_CACHE] = /tmp/.python-eggs
import sys,datetime,MySQLdb,socket,paramiko
def final_check_mysql():
    status = "true"
    try:
        conn = MySQLdb.Connect(host=xxx,port=3306,user=root,passwd=xxx,db=zabbix)
        cur = conn.cursor()
        cur.execute("show slave status;")
        result = cur.fetchall()
        io_thread = result[0][10]
        sql_thread = result[0][11]
        seconds_behind_master = result[0][32]
        #print  io_thread,sql_thread
        cur.close()
        conn.close()
    except Exception,e:
        print  Exception,":",e
    try:
        if io_thread=="Yes" and sql_thread=="Yes" and seconds_behind_master<=1000:
            return 1
        else:
            status = "false"
            return 0

    except Exception,e:
        print Exception,":",e
if __name__==__main__:
    result=final_check_mysql()
    print result


 

  

python 监控mysql主从

标签:pass   exception   cache   use   cut   cep   final   span   exec   

原文地址:https://www.cnblogs.com/yangxiaochu/p/9830221.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!