Chinaunix首页 | 论坛 | 博客
  • 博客访问: 120312
  • 博文数量: 22
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 187
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-03 21:11
文章分类
文章存档

2015年(5)

2014年(17)

分类: 系统运维

2014-12-25 11:55:10

到新公司要求会Python,自己硬着头皮前进,自己研究,觉得和shell完全就是两个不同的概念。血吧呀
自己写的第一个Python,还有待加强。监控mysql的主从同步状态,还在写报警模块
vim mysqlslave.py
#!/usr/bin/python
#conding=utf8
##mysqlstatus
import MySQLdb
import MySQLdb as mdb
import sys

try:
    con = mdb.connect('127.0.0.1', 'root', '123456');
    cur = con.cursor(MySQLdb.cursors.DictCursor)
    cur.execute('show slave status;')
    sql = cur.fetchall()
finally:
    if con:
        con.close()

    if sql[0]['Slave_IO_Running'] == 'Yes' and sql[0]['Slave_SQL_Running'] == 'Yes':
        print "Slave_IO_Running:",sql[0]['Slave_IO_Running']
        print "Slave_SQL_Running:",sql[0]['Slave_SQL_Running']
        print "==="*5
    else:
        print "Slave_IO_Running:",sql[0]['Slave_IO_Running']
        print "Slave_SQL_Running:",sql[0]['Slave_SQL_Running']
        print "==="*5
阅读(1707) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~