#!/usr/bin/env python #_*_coding:utf8 _*_ import MySQLdb import datetime #qps import time try: conn=MySQLdb.connect(host="192.168.1.114",user="dlan",passwd="root123",port=3306) cur=conn.cursor() while True: sql = ‘‘‘show global status where variable_name in(‘com_select‘,‘com_insert‘,‘com_delete‘,‘com_update‘,‘com_insert_select‘,‘uptime‘)‘‘‘ cur.execute(sql) aa = cur.fetchall() aa=list(aa) delete = int(aa[0][1]) insert1 = int(aa[1][1]) insert2 = int(aa[2][1]) select = int(aa[3][1]) update = int(aa[4][1]) uptime1 = int(aa[5][1]) qps1=delete+insert1+insert2+select+update time.sleep(3) while True: sql = ‘‘‘show global status where variable_name in(‘com_select‘,‘com_insert‘,‘com_delete‘,‘com_update‘,‘com_insert_select‘,‘uptime‘)‘‘‘ cur.execute(sql) data = cur.fetchall() data = list(aa) delete_2 = int(aa[0][1]) insert_2 = int(aa[1][1]) insert2_2 = int(aa[2][1]) select_2 = int(aa[3][1]) update_2 = int(aa[4][1]) uptime2_2 = int(aa[5][1]) qps2 = delete_2 + insert_2 + insert2_2 + select_2 + update_2 uptime=uptime2_2-uptime1 print (qps2-qps1)/uptime break except MySQLdb.Error,e: print "MySQL error%d:%s"%(e.args[0],e.args[1])
时间: 2025-01-20 21:29:12