534523 发表于 2016-12-7 08:16:52

MySQL_qps

#!/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)
      insert1 = int(aa)
      insert2 = int(aa)
      select = int(aa)
      update = int(aa)
      uptime1 = int(aa)
      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)
            insert_2 = int(aa)
            insert2_2 = int(aa)
            select_2 = int(aa)
            update_2 = int(aa)
            uptime2_2 = int(aa)
            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,e.args)
页: [1]
查看完整版本: MySQL_qps