#!/usr/bin/env
python
#This script is u
sed check mysql replcation some table
# -*- coding: utf-8 -*-
#site: www.jb200.com
#
import sys,time,
MySQLdb,threading
import ConfigParser
class Check:
def __init__(self):
self.w =[]
self.table = table
def conf(self):
fp = ConfigParser.ConfigParser()
fp.readfp(open('config.ini'))
iplist = fp.get("global", "iplist")
return iplist
def wd(self,table):
iplist = self.conf()
hostlist = []
self.w = []
threads = []
for i in iplist.split(";"):
hostlist.append(i.split(","))
for i in range(len(hostlist)):
host = hostlist[i][0]
hostname = hostlist[i][1]
t = threading.Thread(target=self.mysql_check,args=(host,hostname,i))
threads.append(t)
t.start()
time.sleep(0.05)
for i in range(len(hostlist)):
threads[i].join()
self.w.sort()
for r in range(len(self.w)):
print self.w[r]
def mysql_check(self,host,hostname,i):
try:
conn = MySQLdb.connect(host = host,user = 'user',passwd = 'passwd',connect_timeout=5)
cursor = conn.cursor()
sql = "SELECT COUNT(*) FROM %s" % self.table
cursor.execute(sql)
alldata = cursor.fetchall()
count = alldata[0][0]
value = hostname + "t" + str(count)
self.w.append(value)
except:
print "Can not Connect to " + host + " mysql server"
return 0
if __name__ == "__main__":
table_list = ['adb.credit_log','adb.account','ddb.data']
for i in range(len(table_list)):
table = table_list[i]
print "Table Count: " + table
print
boss = Check()
boss.wd(table)
print