mysql-qps统计python脚本(每秒查询处理量)
#!/usr/bin/env python # coding=utf-8 import time import sys import os import MySQLdb conn = MySQLdb.connect(host=‘127.0.0.1‘,port=3306,user=‘root‘,passwd=‘abc.123‘, charset=‘utf8‘) conn.autocommit(True) cursor=conn.cursor() while True: diff = 1 sql = "show global status where Variable_name in(‘com_select‘,‘com_insert‘,‘com_delete‘,‘com_update‘)" cursor.execute(sql) results = cursor.fetchall() first = [] for rec in results: first.append(rec[1]) time.sleep(diff) sql = "show global status where Variable_name in(‘com_select‘,‘com_insert‘,‘com_delete‘,‘com_update‘)" cursor.execute(sql) results = cursor.fetchall() second = [] for rec in results: second.append(rec[1]) qps = 0 tps = 0 for i in range(0, 4): if i != 0: b = int(second[i]) - int(first[i]) tps += b a = int(second[i]) - int(first[i]) qps += a print ‘qps = %s‘%(qps/diff) print ‘tps = %s‘%(tps/diff) conn.close()
本文出自 “我的运维博客” 博客,请务必保留此出处http://linuxpython.blog.51cto.com/10015972/1643779
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。