【MySQL】計算 TPS,QPS 的python 指令碼
#!/usr/bin/env python
#coding=utf-8
""" 以不同方式獲取mysql中的tps,qps,並做對比 """
import time
import sys
import os
import MySQLdb
import dbconn
def main() :
try:
conn = MySQLdb.connect(host=dbconn.DB_HOST,port=int(dbconn.DB_PORT),user=dbconn.DB_USER,passwd=dbconn.DB_PASS, charset='utf8')
except MySQLdb.ERROR,e:
print "Error %d:%s"%(e.args[0],e.args[1])
exit(1)
conn.autocommit(True)
cursor=conn.cursor()
diff = 1
mystat1={}
mystat2={}
sql = "show global status where Variable_name in ('Com_commit','Com_delete','Com_insert','Com_rollback','Com_select','Com_update','Questions');"
while True:
try :
cursor.execute(sql)
results1 = cursor.fetchall()
mystat1=dict(results1)
time.sleep(diff)
cursor.execute(sql)
results2 = cursor.fetchall()
mystat2=dict(results2)
Com_diff = (int(mystat2['Com_commit']) - int(mystat1['Com_commit']) ) / diff
del_diff = (int(mystat2['Com_delete']) - int(mystat1['Com_delete']) ) / diff
ins_diff = (int(mystat2['Com_insert']) - int(mystat1['Com_insert']) ) / diff
rol_diff = (int(mystat2['Com_rollback']) - int(mystat1['Com_rollback']))/ diff
sel_diff = (int(mystat2['Com_select']) - int(mystat1['Com_select']) ) / diff
upd_diff = (int(mystat2['Com_update']) - int(mystat1['Com_update']) ) / diff
que_diff = (int(mystat2['Questions']) - int(mystat1['Questions']) ) / diff
qps_s = sel_diff
tps_iud = del_diff+ins_diff+upd_diff
qps_ques=que_diff
tps_Com_rol= Com_diff + rol_diff
print 'qps_s = %s , qps_ques = %s , tps_iud = %s ,tps_Com_rol = %s' %(qps_s ,qps_ques, tps_iud,tps_Com_rol)
except KeyboardInterrupt :
print "exit .."
sys.exit()
conn.close()
if __name__ == '__main__':
main()
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25723371/viewspace-1742467/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL實時計算QPS,TPS的SHELL指令碼兩例MySql指令碼
- 如何計算MySQL QPS和TPS的值MySql
- MySQL中TPS和QPS的計算方式MySql
- mysql狀態檢視 QPS/TPS/快取命中率檢視MySql快取
- 實用QPS和TPS高的高效分析方法
- 如何提高系統的吞吐量(QPS/TPS)
- 透過原始碼看看Redis中如何計算QPS原始碼Redis
- SQL 的後計算指令碼SQL指令碼
- 樹莓派 redis 壓力測試 QPS 和 TPS樹莓派Redis
- 用python指令碼計算某一個檔案的行數Python指令碼
- python監控mysql主從指令碼PythonMySql指令碼
- MySQL指令碼MySql指令碼
- MySQL對所有表收集統計資訊(Python 2指令碼)MySqlPython指令碼
- python編寫的簡單的mysql巡檢指令碼PythonMySql指令碼
- 簡述 QPS、TPS、併發使用者數、吞吐量關係
- MySQL上雲同步指令碼-Python3MySql指令碼Python
- python的個稅計算程式碼Python
- 適合時間序列資料的計算指令碼指令碼
- 計算表空間使用率指令碼指令碼
- MySQL 常用指令碼MySql指令碼
- elasticsearch算分指令碼Elasticsearch指令碼
- MySQL 每天自行統計慢日誌 指令碼MySql指令碼
- python寫的簡單分組統計指令碼Python指令碼
- 峰值QPS/QPS/PV/UV/伺服器數量/併發數/吐吞量/響應時間計算公式伺服器公式
- mysql sql 行為的統計--一個很有用的指令碼MySql指令碼
- mysql巡檢指令碼MySql指令碼
- Mysql replication check指令碼MySql指令碼
- mysql監控指令碼MySql指令碼
- mysql時間指令碼MySql指令碼
- mysql kill程式指令碼MySql指令碼
- mysql備份指令碼MySql指令碼
- mysql簡單的碎片清理指令碼MySql指令碼
- MySQL增量備份的指令碼(innobackupex)MySql指令碼
- mysql的一個備份指令碼MySql指令碼
- 檢測mysql狀態的指令碼MySql指令碼
- MySQL批量轉換表名為小寫(Python指令碼)MySqlPython指令碼
- 系統吞吐量、TPS(QPS)、使用者併發量、效能測試概念和公式公式
- 雲端計算面試題及答案,常見的Shell指令碼面試題面試題指令碼