Ultra-easy to view MySQL master-slave delay script 1 code logic
Very simple, Python even MySQL, then show slave status, and then take 2 parameters, followed by a log module, and then do a loop, 5s once.
2. Code Ontology
Some of the sensitive information is missing:
ImportMySQLdbImportLoggingImportTimeFormat ='% (asctime) -15s% (message) s 'Logging.basicconfig (filename='/tmp/slave.log ', level=logging. Debug,format=format)#logging. Basicconfig (Format=format)Dbuser ="XX"Dbpass ="XX"dbname ="XX"D=[]d.append (' xx.mysql.rds.aliyuncs.com ') D.append (' xx.mysql.rds.aliyuncs.com ') D.append (' xx.mysql.rds.aliyuncs.com ') D.append (' xx.mysql.rds.aliyuncs.com ') def get_vars(thedb):DB1 = MySQLdb.connect (thedb,dbuser,dbpass,dbname)#db1 = MySQLdb.connect (' rdso8nxo733x5hq8q2a1.mysql.rds.aliyuncs.com ', dbuser,dbpass,dbname)c = Db1.cursor () C.execute ("show slave Status") ret = C.fetchone () c.close () Db1.close ()return(ret[ +],ret[ the]) while True: forIinchD:PrintI (V1,V2) = Get_vars (i)#print "seconds_behind_master:%s \nsql_delay:%s\n"% (ret[32],ret[42])Logging.debug (' seconds_behind_master:%s| sql_delay:%s ', V1,v2)Print "seconds_behind_master:%s \nsql_delay:%s\n"% (V1,V2) Logging.debug (' End ') Time.sleep (5)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Script that was previously written to detect MySQL delays from the server